开发者

Get the integer inside the URL in PHP

Suppose I am reading a web page and the URL is "http://example.com/term/11,23". How can I use P开发者_高级运维HP to get ONLY the integer in the URL?


You can do this way:

$str = 'http://example.com/term/11,23';
echo end(explode('/', $str));

Result:

11,23


<?php
$url = 'http://example.com/term/11,23';
preg_match_all('#(\d+)#', $url, $matches);
print_r($matches); //outputs array([0]=>11,[1]=>23)
?>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜