Php obtains the file extension in the url.
- // Retrieve the file extension in the url
- $ Url = "http://sdk.tools.sinaapp.com/index.php? Appname = beipiao & version = 1 ";
- Function getFileName ($ url ){
- $ A = explode ('? ', $ Url );
- $ 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.
- $ C = substr ($ a [0], $ B + 1, 3); // substr (operated string, start position, [end position]) returns part of the string
- Return $ c;
- }
- Echo getFileName ($ url )."
";
- // Method 2
- 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 ));
|
File extension, php, url