PHP获取URL的最后部分路由

Published
2022-07-16
浏览次数 :  49

要获取到url的最后部分,要用到preg_match() 函数。

比方说下面是我们要提取的网址:

$websiteAddress='https://www.tutorialspoint.com/java/java_questions_answers/9989809898'

获取url最后部分的写法:

if(preg_match("/\/(\d+)$/",$websiteAddress,$recordMatch)){
   $lastResult=$recordMatch[1];
}
echo "The result is as follows:",$lastResult;
Dislike
  • 标签1
  • 标签1
  • 标签1
Top