Page 1 sur 1

Parser un fichier avec des expressions régulières

Posté : 11 juil. 2005, 12:26
par goeland
Je pars d'un fichier texte avec un squelette qui est celui-ci :

Code : Tout sélectionner

<tr> <td ALIGN='CENTER' bgcolor='#EBEBEB'><font size=1>AA</font></td> <td ALIGN='LEFT' bgcolor='#EBEBEB'><font size=2><BB</font>></td> <td ALIGN='LEFT' bgcolor='#EBEBEB'><font size=1>CC</font></td> <td ALIGN='CENTER' bgcolor='#EBEBEB'><font size=1>DD</font></td> <td ALIGN='RIGHT' bgcolor='#EBEBEB'><font size=1>EE</font></td> <td ALIGN='CENTER' bgcolor='#EBEBEB'><font size=1>FF</font></td> </tr> <tr> <tr> <td ALIGN='CENTER' bgcolor='#EBEBEB'><font size=1>AA'</font></td> <td ALIGN='LEFT' bgcolor='#EBEBEB'><font size=2><BB'</font>></td> <td ALIGN='LEFT' bgcolor='#EBEBEB'><font size=1>CC'</font></td> <td ALIGN='CENTER' bgcolor='#EBEBEB'><font size=1>DD'</font></td> <td ALIGN='RIGHT' bgcolor='#EBEBEB'><font size=1>EE'</font></td> <td ALIGN='CENTER' bgcolor='#EBEBEB'><font size=1>FF'</font></td> </tr> <tr>
j'ai ce code x fois.

J'aimerai regrouper tous les AA dans un 1er tableau, tous les BB dans un 2ème tableau, etc...

Comment je peux faire ?

Posté : 11 juil. 2005, 14:32
par SpaceCowboy

Posté : 11 juil. 2005, 16:18
par goeland
J'aurai dû placer ce post dans débutant :oops:
Modération mere-teresa : il suffit de demander. Zouuuuu !

Je vais utiliser preg_match_all.

Quelle expression je dois utiliser pour sortir de mon texte la chaîne de caractères entourée par :
- > (à gauche de ma chaîne)
- </font></td> (à droite de ma chaîne)

Posté : 11 juil. 2005, 16:42
par goeland
J'ai utilisé ça mais c'est pas terrible

Code : Tout sélectionner

preg_match_all("!>(.*)<\/font>!" , $page, $mots, PREG_PATTERN_ORDER);
il me ressort bien ce que je veux mais il m'en met trop.

Ex : ligne à parser <font size=1>toto</font>
il me ressort <font size=1>toto et je ne veux que toto.