我有两组数据存储在多维数组中。一个存储正则表达式,用于在较大的文本正文中查找整个单词:
Array
(
[red] => Array
(
[0] => ~\b(a)\b~i
[1] => ~\b(b)\b~i
[2] => ~\b(c)\b~i
)
[orange] => Array
(
[0] => ~\b(d)\b~i
)
[green] => Array
(
[0] => ~\b(e)\b~i
)
)
另一个包含替换这些匹配项的内容:
Array
(
[red] => Array
(
[0] => <span class="red">A</span>
[1] => <span class="red">B</span>
[2] => <span class="red">C</span>
)
[orange] => Array
(
[0] => <span class="orange">D</span>
)
[green] => Array
(
[0] => <span class="green">E</span>
)
)
出于示例目的,假设正文是:
敏捷的棕色狐狸跳过了懒狗。a 敏捷的棕色狐狸跳过懒惰的狗。b 敏捷的棕色狐狸跳过懒惰的狗。c 敏捷的棕色狐狸跳过懒惰的狗。d 敏捷的棕色狐狸跳过懒惰的狗。e
PHP 函数preg_replace
不处理多维数组,那么我将如何实现呢?