<?php $correspondances = array( "mot1" => "https://www.lien1.com", "mot2" => "https://www.lien2.com", ); function linkifyText($text, $correspondances) { $pattern = "/#(\w+)#/"; $result = preg_replace_callback($pattern, function($matches) use ($correspondances) { $word = $matches[1]; if (array_key_exists($word, $correspondances)) { $link = '' . $word . ''; return $link; } else { return $word; } }, $text); return $result; } $texte = "Voici un exemple de #mot1# et de #mot2#."; $texteLinkifie = linkifyText($texte, $correspondances); echo $texteLinkifie; ?>