我想使用preg_replace()在文本正文中找到的每个文件扩展名的末尾添加一个字符。
以下是一些示例文本:
$string='http://www.mysite.com/expert/images/imageone.jpghttp://www.mysite.com/expert/images/imagetwo.jpg';这种搜索和替换在TextWrangler中运行良好,只需在文件扩展名后附加一个分号:
(\.(jpg|gif|html?|php|tiff?|pdf|png))
\1;但是,翻译成PHP不起作用,没有任何影响;没有错误。
preg_replace("/(\.(jpg|gif|html|php|tif|tiff|pdf|htm|png))/","\\1;",$string);发布于 2011-01-15 01:51:01
它非常适合我,但您应该尝试使用$1
$string = preg_replace("/.../","$1;",$string);或者将替换放在单引号中:
$string = preg_replace("/.../",'\\1;',$string);https://stackoverflow.com/questions/4694169
复制相似问题