how to get the file name from end
I have different strings but all the stings end with a doc开发者_如何学编程 or pdf file C:\profiles\gim.doc C:\doc\myprofile\profile.pdf
I want to get the file names from the path. Whats the fastest way to do it
basename()
: http://php.net/manual/en/function.basename.php
echo basename("C:\doc\myprofile\profile.pdf");
If you want the filename without the extension...
echo pathinfo('C:\doc\myprofile\profile.pdf', PATHINFO_FILENAME);
use parse_url with argument PHP_URL_PATH
eg:
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
?>
will return
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
/path
精彩评论