-1

I have this code..

$homepage1 = 'datastring=/mac_project/portfolio/kitchen/images/03.jpg';
$trimmed = ltrim($homepage1, 'datastring=/mac_project');
echo $trimmed;

I get the output as folio/kitchen/images/03.jpg. It's missing the /port from the /portfolio directory.

Full output should've been /portfolio/kitchen/images/03.jpg

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126

2 Answers2

4

Why not do the simple str_replace() ?

$homepage1 = 'datastring=/mac_project/portfolio/kitchen/images/03.jpg';
$trimmed = str_replace('datastring=/mac_project','',$homepage1);
echo $trimmed;// "prints" /portfolio/kitchen/images/03.jpg
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
2

The second parameter for ltrim is for character_mask, which means all the chars in the list will be trimmed.

You could use str_replace(), or if you want to replace only at the beginning of the string by preg_replace():

$trimmed = preg_replace('~^datastring=/mac_project~', '', $homepage1);
xdazz
  • 158,678
  • 38
  • 247
  • 274