开发者

Remove text from middle of url

开发者 https://www.devze.com 2023-02-05 00:33 出处:网络
Not the best way to do this...preg_match or rtrim.Can\'t get either working... $insert = http://ww开发者_运维技巧w.site.com/buy/vancouver/house

Not the best way to do this...preg_match or rtrim. Can't get either working...

$insert = http://ww开发者_运维技巧w.site.com/buy/vancouver/house
$insert = rtrim("$insert", "/buy");

No change.

Thanks for the help.


Something like this?

$insert = 'http://www.site.com/buy/vancouver/house';
$insert = str_replace('/buy','',$insert); // http://www.site.com/vancouver/house


If you want to remove only the first occurrence, you can use preg_replace:

$insert = 'http://www.site.com/buy/vancouver/house/buy/dwed';
$insert = preg_replace('#/buy#', '', $insert, 1);
0

精彩评论

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