我有一个文本,只有在匹配整个单词时才需要执行字符串替换。
我正在使用以下代码
$new_subject = preg_replace( '/\b'. $find .'\b' , $replacement , $subject )
(E-G)
$subject = "a brown-fox jumps over the lazy dog";
$find = "brown-fox";
$replacement = "Brown Fox";
所以在preg_replace之后我得到了
$new_subject = "a Brown Fox jumps over the lazy dog".
但我不知道如何执行与下面的科目相同的操作。
$subject = "a <b>brown</b>-fox jumps over the lazy dog"
$subject = "a <b>brown</b>-<span>fox</span> jumps over the lazy dog"
$subject = "a bro<b>wn</b>-fo<mark>x</mark> jumps over the lazy dog"
下面的分别是被替换的文本
$new_subject = "a <b>Brown</b> Fox jumps over the lazy dog"
$new_subject = "a <b>Brown</b> <span>Fox</span> jumps over the lazy dog"
$new_subject = "a Bro<b>wn</b> Fo<mark>x</mark> jumps over the lazy dog"
是否有任何建议/想法可以让我继续前进?