php gets the file extension in url

WBOY
Release: 2016-07-25 08:43:15
Original
1624 people have browsed it
  1. //Get the file extension in the url address
  2. $url = "http://sdk.tools.sinaapp.com/index.php?appname=beipiao&version=1";
  3. function getFileName($url){
  4. $a = explode('?', $url);
  5. $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
  6. $c = substr($a[0], $b+1, 3); //substr(operated String, start position, [end position]) Return part of the string
  7. return $c;
  8. }
  9. echo getFileName($url)."
    ";
  10. //Second method
  11. function getFileNameTwo($ url){
  12. $a = parse_url($url, PHP_URL_PATH); //parse_url() parses the url and returns its components
  13. $b = pathinfo($a, PATHINFO_EXTENSION); //pathinfo()
  14. return $b;
  15. }
  16. print_r(getFileNameTwo($url));
Copy code

file extension, php, url


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template