开发者

Get the integer inside the URL in PHP

开发者 https://www.devze.com 2023-01-30 22:38 出处:网络
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:

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

精彩评论

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