Re: Help with preg_replace() , PLEASE

From: Date: Thu, 13 Mar 2003 18:36:12 +0000
Subject: Re: Help with preg_replace() , PLEASE
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-139576@lists.php.net to get a copy of this message
Got the solution (i wonder why i always get into the list, post the question and end up with the answer 15 minutes later. I'm obviously too nervous and rush for help :-) ) The correct code is the following: <? $text = <<< EOT Let's se a simple sample of how to use a class in PHP <? class CTest { var $variable1; //Propiedad function DoThing() //Método { echo 'esto es una prueba de clase'; echo 'una clase es mejor que nada'; } } ?> And that's all, folks!!! EOT; $text = preg_replace("/(.*)(<\?.*?\?>)(.*)/imse","'\\1<br/>'.highlight_string('\\2', TRUE).'<br/>\\3'",$text); echo $text; ?> The error was the TRUE parameter to highlight_string(). The RegExp was allright. Note that if you use "" in the PHP code you want to color, you'll receive an error. My solution for that: $text = str_replace("\"","'",$text); As the ' is also colored using highlight_string() So, here it is the solution. Now, i'm running onto making my PHP forum !!! Cya all!!

« previous php.general (#139576) next »