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
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Wed Jun 09, 2004 12:17 pm
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 » Wed Jun 09, 2004 2:41 pm
Yeah, that worked for me too, but stuff was parsed. I'm not at home now, but code with variables and whatnot were problematic.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Wed Jun 09, 2004 4:03 pm
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 » Sat Jun 26, 2004 4:37 pm
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 » Wed Dec 01, 2004 4:07 pm
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!!