preg_replace 正则替换

最后更新于:2022-04-02 02:29:31

[TOC] ## 替换单个 ``` $res = preg_replace("/abc/","ab-","abcdec"); print_r($res); // ab-dec ``` ## 替换多个 ``` $res1 = preg_replace(["/abc/","/dec/"],["ab-","de-"],"abcdec"); print_r($res1); // ab-de- ``` ## 用匹配的值替换 ``` $res = preg_replace("/(ab)c/",'--${1}--',"cabc"); print_r($res); // c--ab-- ```
';