- //Get the file extension in the url address
- $url = "http://sdk.tools.sinaapp.com/index.php?appname=beipiao&version=1";
- function getFileName($url){
- $a = explode('?', $url);
- $b = strrpos($a[0], '.'); //strrpos (searched string, to find string, [search starting position] ) Find the position of the last occurrence of the string: if found, return the position of the last occurrence; if not found, return false
- $c = substr($a[0], $b+1, 3); //substr(operated String, start position, [end position]) Return part of the string
- return $c;
- }
- echo getFileName($url)."
";
- //Second method
- function getFileNameTwo($ url){
- $a = parse_url($url, PHP_URL_PATH); //parse_url() parses the url and returns its components
- $b = pathinfo($a, PATHINFO_EXTENSION); //pathinfo()
- return $b;
- }
- print_r(getFileNameTwo($url));
Copy code
|