开发者

Extract part of a string in php

开发者 https://www.devze.com 2023-01-09 12:44 出处:网络
i have this kind of string into my db http://www.my开发者_Python百科domain.com/assets/Image/......./image.jpg

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

0

精彩评论

暂无评论...
验证码 换一张
取 消