url: http://blabla.bl/blabla/ss/sd/filename How to get a filename?
+4
A:
http://us2.php.net/manual/en/function.basename.php
It works even on urls.
Carmine Paolino
2009-09-12 08:19:29
A:
Yes it works, but last thing, sometimes basename is aaaa_somewhat. How to delete _somewhat?
matiit
2009-09-12 08:37:55
$behind_underscore = array_pop(explode('_',basename($url)));unlink($behind_underscore);
thephpdeveloper
2009-09-12 08:57:31
+1
A:
Use earcar's suggestion (basename) to get the filename.
BUT, if we're starting with a URL and the filename includes a query string, use Mauris's suggestion as well.
The query string will start with ? (that's how we know it's not part of the filename) and we can use
explode('?', basename($url));
This is summed up by the online PHP manual for basename
pavium
2009-09-12 09:12:00
A:
Given an arbitrary URL, I think you should use basename() together with parse_url(). Something like this:
$parsed_url = parse_url($url);
$path = $parsed_url['path'];
$filename = basename($path);
Denilson Sá
2009-09-12 20:02:25