preg_replace start of line

From: Date: Wed, 09 Apr 2003 10:31:37 +0000
Subject: preg_replace start of line
Groups: php.general 
Request: Send a blank email to php-general+get-143036@lists.php.net to get a copy of this message
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">&gt; blablabla </span> My difficulty lies with telling preg_replace to look for 'beginning of the line' and '&gt;' 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 ('|(&gt;[^\n]*)(\n)|',"<span class=\"quot\">$1</span>$2" ,$txt ); echo "<table><tr><td> $txt </td></tr></table>\n"; } but it catches all '&gt;', 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 ('|(^&gt;[^\n]*)(\n)|',"<span class=\"quot\">$1</span>$2" ,$txt ); it catches nothing at all. What gives ? j. -- this mail was scanned for viruses aaton.com

« previous php.general (#143036) next »