1、一个描述内容,形如:<p><img src="file:///C:/Users/Administrator/Desktop/测试/data/5201608091357/contentPic/麻短裙16/1643805e-1.jpg" /><br /><img src="file:///C:/Users/Administrator/Desktop/测试/data/5201608091357/contentPic/麻短裙16/1643805e-2.jpg" /><br /><img src="file:///C:/Users/Administrator/Desktop/测试/data/5201608091357/contentPic/麻短裙16/1643805e-3.jpg" /><br />
2、现在我的需求是批量替换src中的图片路径,能够改成路径为/upload/img/,请问正则改怎么写呢?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
str_replace('file:///C:/Users/Administrator/Desktop/测试/data/5201608091357/contentPic/麻短裙16/','/upload/img/',$str)
1.因为你的前缀是固定的话,用str_replace的效率其实更高的。
2.如果不是固定的话,可以参考以下的方法
preg_replace_callback3.调试记得用查看源代码的形式。