[php]un probleme de regexp

Fermé
programmeur_fou - Modifié par programmeur_fou le 24/06/2010 à 22:53
Leviathan49 Messages postés 257 Date d'inscription jeudi 10 juin 2010 Statut Membre Dernière intervention 22 juillet 2011 - 25 juin 2010 à 11:13
Bonsoir,

voici mon problème:
je code en php une colorisation syntaxique du html.
Jusqu'ici tout va bien
Mais, je suis confronté à un problème qui me rend fou.
Lorsque je cherche à colorer les balises, la regex n'est pas prise en compte.
Par exemple:

function colorer($code)
{
$code_regexp = preg_replace('#</?.+>#iU','<span style="color:red">$0</span>',$code);
return $code_regexp;
}
echo colorer($code);

Idem pour les attributs.
Une solution?

Merci


Message aux modos: Est-ce possible de déplacer ce post dans le forum webmastering?
A voir également:

2 réponses

programmeur_fou
25 juin 2010 à 10:57
up?
0
Leviathan49 Messages postés 257 Date d'inscription jeudi 10 juin 2010 Statut Membre Dernière intervention 22 juillet 2011 70
Modifié par Leviathan49 le 25/06/2010 à 11:50
En changeant ta regex par #</?[^>]+>#U
j'obtiens :
test :
$html = "<p>du grand n'importe quoi <b>en HTML</b> commeici <br/> <img height=\"20\" src=\"http://uneURL/un_chemin/image1.jpg\" width=\"10\"> ou encore là <img src=\"../un_autre_chemin/image2.jpg\" height=\"20\" width=\"10\"></p>";
=>
<span style="color:red"><p></span>du grand n'importe quoi <span style="color:red"><b></span>en HTML<span style="color:red"></b></span> commeici <span style="color:red"><br/></span> <span style="color:red"><img height="20" src="http://uneURL/un_chemin/image1.jpg" width="10"></span> ou encore là <span style="color:red"><img src="../un_autre_chemin/image2.jpg" height="20" width="10"></span><span style="color:red"></p></span>

Est-ce ce que tu veux ?

Edit si tu veux que le span soit autour des balises <span ...><b> </b></span>
La solution est sur ce post
https://forums.commentcamarche.net/forum/affich-18264722-php-les-expressions-regulieres#2
0