[SOLVED]highlight_string, but not all?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

ok, this worked for me (with multiple code blocks):o

Code: Select all

$output = preg_replace('|\[div](.*?)\[/div]|ise',"highlight_string('\\1',true)", $row['body']);
echo $output;
edit I ended up doing the following to sort the newlines/br's out.

Code: Select all

$output = preg_replace('|\[div](.*?)\[/div]|ise',"str_replace('<br />', '', highlight_string('\\1',true))", $row['body']);
echo nl2br($output);
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Yeah, that worked for me too, but stuff was parsed. I'm not at home now, but code with variables and whatnot were problematic.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Yeah, the one above is slightly different that previos ones (notice the different quotes). I too was getting parse errors as it was trying to parse the variables that was in the code from the db, but the above solved it (did for me anyway ;))
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

I've been out of this game for a while, and this worked great. Thanks Mark.

Only thing I can't figure out is how to replace the [div] with <div class="innercode"></div>. This has the background like the forums here.
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Wahoo! Finally got it!

Code: Select all

$output = preg_replace('|\[div](.*?)\[/div]|ise',""<div class='div_code'>".highlight_string(stripslashes('\\1'),true)."</div>"", $row['body']);

echo $output;
Thanks a ton you guys!!
Post Reply