$re = "/<body>.*^(.+)(^.*?^)(.+)(^<\\/body>.*?)
/smU";
Citation
The two (.+) are supposed to match the first and last lines within the <body> tag. The /s option (dot all) is needed so the .* can also match newlines. The /m option (multiline) is needed so that the ^ can match newlines. The /U option (ungreedy) is needed so that the .* and .+ will only gobble up the minimum number of characters necessary to get to the character following the * or +. The exception to this, however, is that the .*? temporarily overrides the /U setting on .* turning it from non greedy to greedy. In the middle, this ensures that all the lines except the first and last (within the <body> tag) are put into $aMatch[2]. At the end, it ensures that all the remaining characters in the string are gobbled up, which could also have been achieved by .*)\\z/ instead of .*?)/
Et si je fais :
$fichnew = preg_replace("/<div[\s]*id=\"tutu\">(.*)<\
/div>/smiU", "<h3>$1</h3>", $fich);
Hé bien oh miracle ça marche... Voici le mode ungreedy:
Citation
U (PCRE_UNGREEDY)
Cette option inverse la tendance à la gourmandise des expressions rationnelles. Vous pouvez aussi inverser cette tendance au coup par coup avec un ?. De même, si cette option est activée, le ? rendra gourmand une séquence. Cette option n'est pas compatible avec Perl. Elle peut aussi être mise dans le masque avec l'option ?U dans le pattern ou par un point d'interrogation avant le quantifieur (.e.g. .*?).
En utilisant "?" après "*" tu as activé le mode UNGREEDY...
Ce message a été modifié par TheRec - 01 août 2005 - 16:21.