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)
?>
精彩评论