Re: preg_replace start of line
| From: | Marek Kilimajer | Date: | Wed, 09 Apr 2003 11:22:07 +0000 |
| Subject: | Re: preg_replace start of line | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-143046@lists.php.net to get a copy of this message | ||
^ matches beginning of string in perl expresions, use m modifier:
$txt =preg_replace ('|(^>[^\n]*)(\n)|m',"<span class=\"quot\">$1</span>$2" ,$txt );
julien Beauviala wrote:
I'm having difficulties with preg_replace. I'm trying to display quoted text in a different color using a span class : <span class="quot">> blablabla </span> My difficulty lies with telling preg_replace to look for 'beginning of the line' and '>' and 'whatever till \n' and '\n'. Right now I use : while ($row = mysql_fetch_array($result)) {$date=$row['date']; $txt=$row['text'];$txt = htmlentities($txt); $txt =preg_replace ('|(>[^\n]*)(\n)|',"<span class=\"quot\">$1</span>$2" ,$txt );echo "<table><tr><td> $txt </td></tr></table>\n";} but it catches all '>', even those that are not at the beginning of a line. This is expected as I didn't put a '^' at the beginning of the expression. But if I do$txt =preg_replace ('|(^>[^\n]*)(\n)|',"<span class=\"quot\">$1</span>$2" ,$txt );it catches nothing at all. What gives ? j.