你可以使用preg_replace()函数来实现这个替换和重定向的功能。下面是一个示例代码:

$pattern = '/(\/\/[^\/]+)\/([^']+)/';
$replacement = 'https://gimg3.baidu.com/gimg/app=2028&src=$2';

$url = 'http://example.com/image.jpg';
$newUrl = preg_replace($pattern, $replacement, $url);

header('Location: '.$newUrl);
exit;

这个代码将会把原始的图片链接中最后一个'//'前面的内容替换成指定的URL,并通过重定向跳转到新的图片链接。

PHP正则匹配替换图片链接,实现图片重定向

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

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