Bonjour,
Je voudrais faire une fonction / un regex pour remplacer certains mots par des liens dans un texte.
Exemple : Le chat est noir.
Devient : Le
<a href="http://www.chat.org/">chat</a>
est noir.
Je le fais avec un str_replace(), ça fonctionne mais... ça explose mes images. Exemple :
<img src="chat.png" alt="Une photo de chat" />
Devient
<img src="<a href="http://www.chat.org/">chat</a>.png" alt="Une photo de <a href="http://www.chat.org/">chat</a>" />
ce qui explose toute ma page
Comment éviter ce problème ? Est-il possible de le faire avec un regex ?
Merci à vous
Partager