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
|
<?php
// Source : http://www.expreg.com/lire-Chaines-source
function cherche_mot_sans_bbcode($chaine,$mot_a_trouver) {
$tab = preg_split('`(\[\w+.*?\])`',$chaine,-1,PREG_SPLIT_DELIM_CAPTURE);
foreach($tab as $key=>$val){
if(preg_match('`^\[\w+`',$val)){
$tab[$key] = $val;
}
else {
$tab[$key]=preg_replace('`\b'.$mot_a_trouver.'\b`i','<span style="background-color:#ffcc00">$0</span>',$val);
$count_nombre_de_mot_a_trouver =
}
}
return implode($tab);
}
$chaine = 'Prenons cette chaine --> Les amerindiens : [a href="../amerindiens/autres/black_hills.php" target="_blank"]amerindiens[/a][br]Prenons ce mots à rechercher --> amerindiens[br]Un exemple, en image [img src="amerindiens.gif" alt="amerindiens" /].[br]Les amérindiens (avec un accent), un amerindien (au singulier), Les amerindiens (pluriel)';
echo cherche_mot_sans_bbcode($chaine,'amerindiens');
?> |
Partager