我想替换从example.com
到sample.com
的所有字符串值,不包括图像扩展名.png
、.jpeg
、.jpg
等。
$body = ' www.example.com, example.com, example.com/hello.html, example.com/logo.png, example.com/yourbaby.php , example.com/newimage.jpg, www.example.com/newimage.jpg';
//values
$oldomain = ['example.com','www.'];
$newdomain= ['sample.com', ''];
$excludeextension = [".png", ".jpg", ".jpeg"];
//Replace
$body = str_replace($olddomain, $newdomain, $body);
$body = str_replace($excludeextension, '', $body);
//output
echo $body;
我要查找的输出:
sample.com, sample.com, sample.com/hello.html, example.com/logo.png, sample.com/yourbaby.php , example.com/newimage.jpg, www.example.com/newimage.jpg
期望
https://example.com -> https://sample.com
https://www.example.com -> https://sample.com
https://subdomain.example.com -> https://subdomain.sample.com
https://www.example.com/image.png -> https://www.example.com/image.png
https://example.com/image.png -> https://example.com/image.png
1条答案
按热度按时间wgeznvg71#
你可以用
str_replace()
加上一点爆炸和内爆来实现。结果