note 72843 deleted from function.preg-replace by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 20:08:38 +0000 |
| Subject: | note 72843 deleted from function.preg-replace by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127719@lists.php.net to get a copy of this message | ||
Note Submitter: Marc
----
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);
?>