preg_split regex for file name needed
Posted: Thu Oct 22, 2009 2:03 am
Hello, I need help for a preg split regex, to extract the file name in a given url,
so that http://foo.bar/dadadada.jpg
would return dadadada.jpg
and http://foo.bar/da-da.Da-da.jpg
would return da-da.Da-da.jpg
basically it needs to return the file name no matter what character is in the name, (hyphen, period, comma, underscore)
So far what I did was this, but it isn't working.
thank you.
so that http://foo.bar/dadadada.jpg
would return dadadada.jpg
and http://foo.bar/da-da.Da-da.jpg
would return da-da.Da-da.jpg
basically it needs to return the file name no matter what character is in the name, (hyphen, period, comma, underscore)
So far what I did was this, but it isn't working.
Code: Select all
$string = "http://foo.bar/dadadada.jpg";
$keyword = preg_split("#^\w+://\w+\.\w+/([-:a-z0-9]+).(\w+)#i", $string);
echo $keyword[0].".".$keyword[1];