Extract part of a string in php
i have this kind of string into my db
http://www.my开发者_Python百科domain.com/assets/Image/......./image.jpg
and would like to clean it up and make it
image.jpg
how could get the part of the string starting from the right until the first "/" ?
$url = "http://www.mydomain.com/assets/Image/......./image.jpg";
$filename = basename($url);
echo $filename;
You can use the basename function.
basename('http://www.mydomain.com/assets/Image/......./image.jpg');
echo preg_replace('~.+/~', '', $url);
see also parse_url, pathinfo
精彩评论