[英]PHP regexp replace all matches except the first one
我正在使用preg_replace從以下字符串中用\\ n#替換# :
#0 F:\dev\htdocs\cms\lib\Cms.php(76):
ReflectionClass->__construct('Mod_Simple_Top_...')
#1 F:\dev\htdocs\cms\cms.php(45): Cms::renderModules(Array,
#2 F:\dev\htdocs\cms\bootstrap.php(63): require_once('F:\dev\htdocs\c...')
#3 {main}
preg_replace('/#/','\\ n',$ error_message);
問題在於它也替換了第一個匹配項,即; #0 regexp中有任何語法,因此它不應該考慮第一個匹配項。
更換后,只需先移除\\ n。 使用substr($string, 1)
或trim($string)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.