Carl Topham

Move up a level in a PHP string

To remove the last part of a string of words or directory structures in PHP you can use this wonderful bit of code:

$b = substr($a, 0, strrpos($a, " "));

Just replace the " " with "/" for removing the last dir from a string (to go up a level)

Category: Web development

Comments

Add A comment