提取网址的最后一部分

Aut*_*cus 6 php

需要网址的最后一部分

http://example.com然后最后一部分是什么,如果它是http://example.com/i然后最后一部分是我,如果它是http://example.com/i/am/file.php 然后最后部分是file.php

不确定我是否使用正则表达式或什么

Vas*_*kov 19

这是一个简单的例子:

 <?php
     $url = "http://example.com/i/am/file.php";
     $keys = parse_url($url); // parse the url
     $path = explode("/", $keys['path']); // splitting the path
     $last = end($path); // get the value of the last element 
 ?>
Run Code Online (Sandbox Code Playgroud)

我希望这能帮到你;)


Den*_*rdy 5

有一个名为parse_url()的函数.