Use php to analyze the URL to get the file name, directory path, and other data. The principle is to use the PHP explode function to separate strings. To be as efficient as possible, retrieve the file extension from a standard url, and then extend the code to get other data, such as directory path, the principle is to use the explode function of PHP to separate strings.
Example: http://www.abc.com/abc/de/fg.php? Id = 1 need to retrieve php or. php
It is very easy to look at the code directly.
The code is as follows:
$ Url = "http://www.abc.com/abc/de/fg.php? Id = 1 ";
// This is self-written.
Function getUrl ($ url ){
$ Date = explode ('? ', $ Url );
$ Date = basename ($ date [0]);
$ Date = explode ('.', $ date );
Return $ date [1];
}
Var_dump (getUrl ($ url ));
// The following two are obtained online.
Function getExt ($ url ){
$ Arr = parse_url ($ url );
$ File = basename ($ arr ['path']);
$ Ext = explode (".", $ file );
Return $ ext [1];
}
Var_dump (getExt ($ url ));
Function getName ($ url ){
$ W_param = pathinfo ($ url );
$ Str = $ w_param ['extension'];
List ($ type, $ vars) = explode ('? ', $ Str );
Return $ type;
}
Echo 'start3'. date ("Y-m-d H: I: s ");
?>