开发者

Replace part of the string

开发者 https://www.devze.com 2023-03-19 09:47 出处:网络
Echo $var gives me something like http://342.234.243.142/data/somethingmore/ IP-address everytime is different.

Echo $var gives me something like http://342.234.243.142/data/somethingmore/

IP-address everytime is different. Instead of "somethingmore" can something like "/folder/images/2011/gallery/file.jpg" (anything)

H开发者_运维知识库ow do I strip from this string part with the ip and /data/ folder?

$var could become /somethingmore/


$url = 'http://342.234.243.142/data/somethingmore/';
echo basename($url);


$str = "http://342.234.243.142/data/somethingmore/";
$str = explode('/', $str);

print_r($str);


Use this regular expression:

/.*?\/data/

This way you can get a full string after '/data' even if it contains more '/' (slashes). For example, http://342.234.243.142/data/somethingmore/andmore/

0

精彩评论

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