I have two sets of data stored in multidimensional arrays. One stores regular expressions which will be used to find whole words within a larger body of text:
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
)
)
And the other contains what to replace those matches with:
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>
)
)
For exemplary purposes, let's say the body of text is:
The quick brown fox jumps over the lazy dog. a The quick brown fox jumps over the lazy dog. b The quick brown fox jumps over the lazy dog. c The quick brown fox jumps over the lazy dog. d The quick brown fox jumps over the lazy dog. e
The PHP function preg_replace
doesn't handle multidimensional arrays, so how would I go about accomplishing this?