Bonjour à tous,
je souhaite insérer des liens dans un text lorsque des portions de ce texte sont reconnues.
voila ce que j'ai fait:
ça fonctionne en partie, je souhaite faire un lien que si le mot reconnu (ici microsoft) n'est PAS deja un lien hypertext. Vous pouvez m'aider à faire l'expression reguliere ? svp.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
31
32 <? if(!function_exists('onTheFlyBodyLinks')) { function onTheFlyBodyLinks($t) { function linkTo($matches) { //var_dump($matches); $mystring = $matches[0]; return '<a href="www.microsoft.com">'.$mystring.'</a>'; } $searchTerms = array( "microsoft" => array(39849814), // IT France company ID ); foreach ($searchTerms as $wordToLink => $details) { $pattern = "/".$wordToLink."/is"; $t = preg_replace_callback($pattern, "linkTo", $t); } return ($t); } } $txt = "j'aime bien Microsoft surtout quand ça fonctionne, mais la ça devrait pas fonctionner <a href='http:www.microsoft.fr'>microsoft</a>"; echo onTheFlyBodyLinks($txt); ?>
merci
Partager