Php obtains the file extension in the url.

Source: Internet
Author: User
Php obtains the file extension in the url.

  1. // Retrieve the file extension in the url
  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 (string to be searched, [start position to search]) locate the last occurrence of a string: returns the last occurrence of a string; if not found, false is returned.
  6. $ C = substr ($ a [0], $ B + 1, 3); // substr (operated string, start position, [end position]) returns part of the string
  7. Return $ c;
  8. }
  9. Echo getFileName ($ url )."
    ";
  10. // Method 2
  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 ));


File 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.