1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
<?php
function mon_callback($capture){
global $mot;
if (strtolower($capture[2]) != '</a>'){
return preg_replace('#\b'.$mot.'\b#i', '<a href="">$0</a>', $capture[1]).$capture[2];
} else {
return $capture[1].$capture[2];
}
}
$contents="<p>
abc 567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
abc 567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567
</p>";
$mot='abc';
echo preg_replace_callback('#((?:(?!<[/a-z]).)*)([^>]*>|$)#si', "mon_callback", $contents);
?> |
Partager