OVH Cloud OVH Cloud

Probleme EREGI

3 réponses
Avatar
titi
X-No-Archive: yes
Restrict: no-external-archive

Bonjour,

Je cherche à analyser un fichier XML en PHP

$xmi contient par exemple
<t>Chat</t>
<r>30.00</r>
<t>Chien</t>
<r>12.00</r>
if (eregi("<t>(.+)</t>",$xmi ,$m)) {
return $m[1];
} else {
return "N/A";
}

J'ai essayé : "<t>(.+)</t>" ou "<t>(.*)</t>" ou "<t>(.+)</t>\r\n"
Il me retourne (en HTML): Chat 30.00 Chien


Comment lui indiquer de prendre le premier ou le second.
Je n'ai trouvé aucune documentation en ligne claire.
http://www.commentcamarche.net/javascript/jsregexp.php3
http://www.manuelphp.com/php/function.eregi.php


Merci d'avance.
Cordialement
--
G.M.

3 réponses

Avatar
Olivier Miakinen

$xmi contient par exemple
<t>Chat</t>
<r>30.00</r>
<t>Chien</t>
<r>12.00</r>
if (eregi("<t>(.+)</t>",$xmi ,$m)) {
return $m[1];
} else {
return "N/A";
}

J'ai essayé : "<t>(.+)</t>" ou "<t>(.*)</t>" ou "<t>(.+)</t>rn"
Il me retourne (en HTML): Chat 30.00 Chien


Il vaut mieux utiliser les expressions régulières de type PERL qui sont
beaucoup plus puissantes et permettent cela facilement de plusieurs
façons, par exemple avec l'option U.

"|<t>(.+)</t>|" -> "Chat</t>n<r>30.00</r>n<t>Chien".
"|<t>(.+)</t>|U" -> "Chat", puis "Chien".
"|<t>(.+?)</t>|" -> "Chat", puis "Chien" (non testé).

Je n'ai trouvé aucune documentation en ligne claire.
http://www.commentcamarche.net/javascript/jsregexp.php3
http://www.manuelphp.com/php/function.eregi.php


http://www.php.net/manual/fr/function.preg-match.php
http://www.php.net/manual/fr/reference.pcre.pattern.modifiers.php
http://www.php.net/manual/fr/reference.pcre.pattern.syntax.php

Bonne lecture !

Avatar
Fredchou
Je cherche à analyser un fichier XML en PHP


Plus simple, il y a aussi : http://www.php.net/manual/fr/ref.simplexml.php
--
Fredchou
mailto:

Avatar
Fredchou
Je cherche à analyser un fichier XML en PHP


Tu peux également utiliser un analyseur XML. Par exemple :
http://www.php.net/manual/fr/ref.xml.php

--
Fredchou
mailto: