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 30
|
$message = "
[p]Ligne 1 Monument Valley[/p]
[p]Ligne 2 [a href=../arizona/grand-canyon/grand-canyon.php target=_blank]Grand Canyon[/a][/p]
";
function liens_automatiques($chaine,$mot_a_trouver,$remplacement){
$tab = preg_split('`(<\w+.*?>)`U',$chaine,-1,PREG_SPLIT_DELIM_CAPTURE);
foreach($tab as $key=>$val){
if(preg_match('`^<\w+`',$val)) {
$tab[$key] = $val;
}
else {
$tab[$key] = preg_replace('`'.$mot_a_trouver.'`i',$remplacement,$val);
}
}
return implode($tab);
}
$remplacer = preg_replace( "/arizona/i", '[a target=_blank href=../arizona/parcs-villes-arizona.php]Arizona[/a]', $message);
$message = preg_replace( "/grand canyon|grd canyon/i", '[a target=_blank href=../arizona/grand-canyon/grand-canyon.php]Grand Canyon[/a]', $message);
$message = preg_replace( "/monument valley/i", '[a target=_blank href=../arizona/monument-valley/monument-valley.php]Monument Valley[/a]', $message);
echo "<pre>".$message."</pre>"; |
Partager