note 91019 added to function.preg-replace

From: Date: Thu, 21 May 2009 08:48:15 +0000
Subject: note 91019 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-155821@lists.php.net to get a copy of this message
en PHP 5: Pour l'interprétation des BBcode, il faut un masque non gourmand, donc il fait utiliser les modificateurs x = PCRE_EXTENDED: sinon la séquence (.*?) n'est pas évaluée correctement g = PCRE_GLOBAL: sinon le remplacement s'arrête après la première occurrence. si le texte comporte des retour à la ligne, on utilisera m = PCRE_MULTILINE voici un exemple fonctionnel $bbcode = array( "/\[b\](.*?)\[\/b\]/mxg" => "<b>$1</b>", "/\[u\](.*?)\[\/u\]/mxg" => "<u>$1</u>", "/\[url\=(.*?)\](.*?)\[\/b\]/mxg" => "<a href='$1'>$2</a>" ); $text = "[b]Text[/b][u]Text[/u]"; $text = preg_replace(array_keys($bbcode), Pour vous aider a mettre au point les regexp, il existe quelques logiciels spécialisés comme RegExpBudy (commercial), RegexCoach (propriétaire mais gratuit...) et JH RegExp Builder qui est meilleur car il prend en charge toute les syntaxes et sous licence libre (c'est celui que j'utilise). ---- Server IP: 193.190.67.9 Probable Submitter: 213.219.182.218 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/91019 Del: integrated -- https://master.php.net/note/delete/91019/integrated Del: useless -- https://master.php.net/note/delete/91019/useless Del: bad code -- https://master.php.net/note/delete/91019/bad+code Del: spam -- https://master.php.net/note/delete/91019/spam Del: non-english -- https://master.php.net/note/delete/91019/non-english Del: in docs -- https://master.php.net/note/delete/91019/in+docs Del: other reasons-- https://master.php.net/note/delete/91019 Reject -- https://master.php.net/note/reject/91019 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#155821) next »