开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜