need help to cut a string with PHP
I have a string:
$str = "http://www.abc.com/xxx/xxx/v54/c505/1.html";
How do I cut th开发者_运维问答e trailing 1.html
off ?
The result I desire is http://www.abc.com/xxx/xxx/v54/c505/
.
Use dirname()
$newStr = dirname($str) . '/';
$str = substr($str, 0, strrpos($str, '/') + 1);
CodePad.
You can use dirname() --
$str = "http://www.abc.com/xxx/xxx/v54/c505/1.html";
$dir = dirname($str);
精彩评论