Problem with regex and highlight_string...

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Problem with regex and highlight_string...

Post 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?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Problem with regex and highlight_string...

Post by Ollie Saunders »

Lose the e modifier on the end of the regex pattern.
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Re: Problem with regex and highlight_string...

Post 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...
Post Reply