你可以使用 preg_replace 函数来实现这个功能。下面是一个示例代码:

$str = "mac://example.com/image.jpg?url=http://22.com/image.jpg";
$pattern = '/(.*//)(.*)/';
$replacement = 'https://gimg3.baidu.com/gimg/app=2028&src=$2';
$result = preg_replace($pattern, $replacement, $str);

echo $result;

输出结果为:

https://gimg3.baidu.com/gimg/app=2028&src=example.com/image.jpg?url=http://22.com/image.jpg

这样就将字符串中最后一个“//”前面的内容替换成了“https://gimg3.baidu.com/gimg/app=2028&src=”。

PHP 正则表达式替换字符串中最后一个“//”前面的内容

原文地址: https://www.cveoy.top/t/topic/qmki 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录