Reputation: 2225
$dir = '/web99/web/direcotry/filename';
I need to drop '/web99/web/' from the directory on the fly.
I tried:
$trimmed = ltrim($dir, "/web99/web/");
however if a directory started with a w,e,b,9 the first letter of the directory was cut off.
How can I drop only what I want and not every character like that?
Upvotes: 1
Views: 1680
Reputation: 3156
I would use strtr(), so if you need other string replacements, editing will be easy :
$trimmed = strtr($dir, array('/web99/web/'=>''));
Upvotes: 0
Reputation: 42496
You could just use str_replace
if you know that it will never be anywhere else in the path:
$trimmed = str_replace('/web99/web/', '', $dir);
If you wanted to be really safe, you could use preg_replace
to get the beginning of the string:
$trimmed = preg_replace('~^/web99/web/~', '', $dir);
Upvotes: 0