note 72843 added to function.preg-replace
| From: | Marc at osu1 dot php dot net | Date: | Fri, 02 Feb 2007 20:26:03 +0000 |
| Subject: | note 72843 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-122578@lists.php.net to get a copy of this message | ||
I have a free text field, and I wanted users to be able to style it up a bit with color using
<color>some text</color> for a couple common colors. When the field is displayed as
readonly, I wanted to replace these tags, which can be nested, with the appropriate html markup.
Here we go:
<?php
$value = "Some <red>value with <green>nested</green> colors
<black>!!!!!</black></red>";
//Add more html compliant colors as required :-)
$colors = "blue|black|brown|cyan|gray|green|orange|pink|purple|red|yellow";
do{
$value = preg_replace("/<($colors)>(.*)</\\1>/i", "<font
style='color: $1;'>$2</font>", $value, -1, $count);
}while($count);
?>
----
Server IP: 216.235.15.211
Probable Submitter: 216.9.243.111
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/72843
Del: integrated -- https://master.php.net/note/delete/72843/integrated
Del: useless -- https://master.php.net/note/delete/72843/useless
Del: bad code -- https://master.php.net/note/delete/72843/bad+code
Del: spam -- https://master.php.net/note/delete/72843/spam
Del: non-english -- https://master.php.net/note/delete/72843/non-english
Del: in docs -- https://master.php.net/note/delete/72843/in+docs
Del: other reasons-- https://master.php.net/note/delete/72843
Reject -- https://master.php.net/note/reject/72843
Search -- https://master.php.net/manage/user-notes.php