【发布时间】:2018-10-02 21:16:04
【问题描述】:
输入文字:工学院、医学院
所需输出:教育学校,教育学校
规则:后面跟“school of”的任何单词都需要替换为“education”
$inputext = "school of engineering, school of medicine";
$rule ="//s/";
$replacetext = "education";
$outputext = preg_replace($rule, $replacetext, $inputext);
echo($outputext);
感谢您的任何建议。
【问题讨论】:
-
这是一个无效的reges
//s/,因为你有一个未转义的分隔符。preg_replace('/(school of )[-a-z0-9_]+\b/i', '\1'.$replacetext, $inputext) -
preg_replace("/\\bschool of .+?\\b/", "school of education", $inputext);
标签: php regex preg-replace