Wow, that's intense. All kinds of functions I've never heard of. In fact after reading the manual page on create_function(), I still don't understand it. $matches doesn't exist anywhere outside of create_function()???
Anyway, it's doing the same thing my original preg_replace() was doing (finding matches inside tags). Here's the new function, minus the array stuff:
<?php
$test="<table>\r\n<tr>\r\n\t<td><img src=\"somestring.jpg\" alt=\"\"></td>\r\n</tr>\r\n<tr>\r\n\t<td>somestring</td>\r\n</tr>\r\n</table>\r\n";
$term = 'somestring';
$test = preg_replace_callback(
'/>(.+?)</',
create_function(
'$matches',
'return preg_replace("/\b(' . preg_quote($term) . ')\b/", "<span style=\"background:#FF0;\">\\\1</span>", $matches[0]);'
),
$test
);
echo $test;
?>
and the output
<table>
<tr>
<td><img src="<span style="background:#FF0;">somestring</span>.jpg" alt=""></td>
</tr>
<tr>
<td><span style="background:#FF0;">somestring</span></td>
</tr>
</table>