PHP gets the file name extension in the URL

Source: Internet
Author: User
  1. //Remove U The file name extension
  2. $url = "Http://sdk.tools.sinaapp.com/index.php?appname=beipiao&version=1" in the RL address;
  3. function GetFileName ($url) {
  4. $a = explode ('? ', $url);
  5. $b = strrpos ($a [0], '. ');//strrpos (the string to be searched for, to find the string, [find where to start]) finds the last occurrence of the string: it returns the last occurrence of the position, or false if not found
  6. $c = substr ($a [0], $b +1, 3); substr (manipulated string, start position, [end position]) returns a portion 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 name extension, PHP, URL
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.