Page 1 of 1

Problem with regex and highlight_string...

Posted: Wed Jul 09, 2008 7:33 pm
by Inkyskin
Hi all, I'm trying to use highlight_string within preg_replace to do some PHP highlighting. I am getting the following error:
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\phpextra\pages\news\read.php(17) : regexp code on line 1

Fatal error: preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Failed evaluating code: <code><span style="color: #000000"> include CLASSES.\'/breadcrumb.class.php\'; $breadcrumb = new breadcrumb; $breadcrumb->add_breadcrumb(\'Home\',\'/\'); $breadcrumb->add_breadcrumb(\'News\',\'/news/\'); $breadcrumb->add_breadcrumb($news_data[\'title\'],\'\'); $page_breadcrumb = $breadcrumb->show_breadcrumb(); </span> </code> in C:\xampp\htdocs\phpextra\pages\news\read.php on line 17
Heres the code:

Code: Select all

$main_content = preg_replace('#\[php\](.*?)\[\/php\]#ise', highlight_string(stripslashes('$1'),true), $main_content);
And heres the example PHP code I'm trying to shove through it:

Code: Select all

 
include CLASSES.'/breadcrumb.class.php';
$breadcrumb = new breadcrumb;
$breadcrumb->add_breadcrumb('Home','/');
$breadcrumb->add_breadcrumb('News','/news/');
$breadcrumb->add_breadcrumb($news_data['title'],'');
$page_breadcrumb = $breadcrumb->show_breadcrumb();
 
I have no idea how to resolve this, any ideas folks?

Re: Problem with regex and highlight_string...

Posted: Wed Jul 09, 2008 7:56 pm
by Ollie Saunders
Lose the e modifier on the end of the regex pattern.

Re: Problem with regex and highlight_string...

Posted: Wed Jul 09, 2008 7:59 pm
by Inkyskin
Thats better, thanks!

For some reason though it's just making all the text black... if I add the <? and ?> symbols in the database it wont show them properly and still format in black...