[PHP] expression reguliere preg_replace Dernière réponse : 24 Janvier 2006 21:02 dans Programmation attentio 24 Janvier 2006 18:00:54 bonsoir, voila, j'ai quelques difficultés avec la fonction preg_replace je veux transformer les <b></b> en et l'inverse mais ca ne marche pas ! Citation :ca marche pas devient ]<r>[]ca marche pas [/B] <? //marche $texte='<b>ca marche</b>'; echo $texte; $pattern2 = array ('#<b>(.*?)</b>#i',); $replace2 = array("[B]$1[/B]"); $texte = preg_replace($pattern2, $replace2, $texte); echo '<br>->'.$texte; //ne marche pas $texte2="<br>[B]ca marche pas[/B]"; $pattern = array ('#[B](.*?)[/B]#i'); $replace = array('<b>$1</b>'); $texte2 = preg_replace($pattern, $replace, $texte2); echo '<br>'.$texte2; merci infiniment de votre aide Autres pages sur : php expression reguliere preg replace | Etre averti des réponses | Alerter Répondre à attentio Lassé par la pub ? Créez un compte SiM07 Expert Programmation 24 Janvier 2006 19:31:16 function bbcode_gras($string) { $string = preg_replace("(\[b\](.+?)\[\/b])is",'<strong>$1</strong>', $string); } | Alerter Répondre à SiM07 attentio 24 Janvier 2006 21:02:22 merci | Alerter Répondre à attentio Lassé par la pub ? Créez un compte Répondre Créer un nouveau sujet Tom's Guide>Forum>Programmation>[PHP] expression reguliere preg_replace> Contenus similaires : Tags : echo
attentio 24 Janvier 2006 18:00:54 bonsoir, voila, j'ai quelques difficultés avec la fonction preg_replace je veux transformer les <b></b> en et l'inverse mais ca ne marche pas ! Citation :ca marche pas devient ]<r>[]ca marche pas [/B] <? //marche $texte='<b>ca marche</b>'; echo $texte; $pattern2 = array ('#<b>(.*?)</b>#i',); $replace2 = array("[B]$1[/B]"); $texte = preg_replace($pattern2, $replace2, $texte); echo '<br>->'.$texte; //ne marche pas $texte2="<br>[B]ca marche pas[/B]"; $pattern = array ('#[B](.*?)[/B]#i'); $replace = array('<b>$1</b>'); $texte2 = preg_replace($pattern, $replace, $texte2); echo '<br>'.$texte2; merci infiniment de votre aide Autres pages sur : php expression reguliere preg replace | Etre averti des réponses | Alerter Répondre à attentio
SiM07 Expert Programmation 24 Janvier 2006 19:31:16 function bbcode_gras($string) { $string = preg_replace("(\[b\](.+?)\[\/b])is",'<strong>$1</strong>', $string); } | Alerter Répondre à SiM07