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
Lundern
Forum Newbie
Posts: 8 Joined: Fri Aug 13, 2004 2:24 am
Post
by Lundern » Fri Aug 13, 2004 2:24 am
Hi, my portal is in the making.
But I need some help, how can I use preg_replace to call out an highlighting from the code function on this forum, for example:
Code: Select all
<?php echo"I want to have this codething on my site.."; ?>
My code goes like this:
Code: Select all
<?php
$q = @mysql_query("SELECT * FROM art where art_id = '".$_GETї'art_id']."' and art_type = '".$_GETї'art_type']."'");
while($r = @mysql_fetch_assoc($q))
{
print("<h3>$rїart_navn]</h3>
$rїingress]
<h3>Artikkelen</h3>
$rїeksart]");
}
?>
The variable called: $[eksart] is where the article is posted, when it finds for example: [*code] [/*code] I want it to be highlighted just like on this forum..
How do I make this? Does anyone here have a useful code I can use?
Thanks for your help!
Best regard,
Ole
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 13, 2004 2:42 am
check on evilwalrus' site.. evilwalrus.com, they've got a few bbcode function scripts there, they aren't fully compliant, but they'll get you started.. or you can try to snag phpbb's bbcode script by downloading their package and loading up bbcode.php from the includes directory..
Lundern
Forum Newbie
Posts: 8 Joined: Fri Aug 13, 2004 2:24 am
Post
by Lundern » Fri Aug 13, 2004 2:47 am
I have already tried that, but the codes they are using is to advanced for me
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 13, 2004 2:50 am
evilwalrus' are pretty tame, compared to the phpbb ones..
Lundern
Forum Newbie
Posts: 8 Joined: Fri Aug 13, 2004 2:24 am
Post
by Lundern » Fri Aug 13, 2004 3:26 am
Yeah, I looked at some codes, this is the best I have found to now:
Code: Select all
/* Code Format */
$message = eregi_replace('\ї*code](ї^ї]*)\ї/*code]', '<b>Code:</b><blockquote style="width: 100%; margin: 3px 8px 3px 16px; color: #000; background-color: #FFF; border: 2px solid #808080; font-size: 8pt;">\\1</blockquote>', $message);
$php_stuff = eregi('\ї*php](ї^ї]*)\ї/php]', $message, $regs);
$message = eregi_replace('\ї*php](ї^ї]*)\ї/php]', '<b>PHP:</b><br><table width="100%" border="0" cellspacing="0" cellpadding="0" style="background-color: #FAFAFA; border: 1px solid #D1D7DC;">
<tr>
<td style="padding-left: 10px; padding-right: 10px; padding-top: 10px; padding-bottom: 10px;">'.highlight_string($regsї1], true).'</td>
</tr>
</table>', $message);
/* Code Format */
But it doesnt work
EDIT: I cant find the variable I have to change with $r[eksart], which is the mysql variable for the article..
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 13, 2004 3:31 am
the basics of it looks like it'd work:
Code: Select all
<?php
$r['eksart'] = preg_replace('#\['.'code](.*?)\#is', '<b>Code:</b><blockquote style="width: 100%; margin: 3px 8px 3px 16px; color: #000; background-color: #FFF; border: 2px solid #808080; font-size: 8pt;">\\1</blockquote>', $r['eksart']);
?>
Lundern
Forum Newbie
Posts: 8 Joined: Fri Aug 13, 2004 2:24 am
Post
by Lundern » Fri Aug 13, 2004 3:44 am
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 13, 2004 3:57 am
right.. because it's not run through the php highlighter...
if you want that, you'll need some fancy footwork:
Code: Select all
<?php
$r['eksart'] = preg_replace('#\['.'php](.*?)\['.'/php]#ise',"'<b>PHP:</b><br><table width="100%" border="0" cellspacing="0" cellpadding="0" style="background-color: #FAFAFA; border: 1px solid #D1D7DC;">
<tr>
<td style="padding-left: 10px; padding-right: 10px; padding-top: 10px; padding-bottom: 10px;">' . highlight_string('\\1',true) . '</td>
</tr>
</table>'", $r['eksart']);
?>
that's untested...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 13, 2004 4:14 am
hmmm might need to add an "addslashes" call to that..not sure..
Lundern
Forum Newbie
Posts: 8 Joined: Fri Aug 13, 2004 2:24 am
Post
by Lundern » Fri Aug 13, 2004 4:16 am
Addslashes didnt work so well as stripslashes did, but then I get all these \ all the time
EDIT: + a error message similar to the one I posted..
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 13, 2004 4:38 am
I was referring to do something more like:
Code: Select all
<?php
$r['eksart'] = preg_replace('#\['.'php](.*?)\['.'/php]#ise',"'<b>PHP:</b><br><table width="100%" border="0" cellspacing="0" cellpadding="0" style="background-color: #FAFAFA; border: 1px solid #D1D7DC;">
<tr>
<td style="padding-left: 10px; padding-right: 10px; padding-top: 10px; padding-bottom: 10px;">' . highlight_string('\\1',true) . '</td>
</tr>
</table>'", stripslashes($r['eksart']));
?>or putting it inside the evaluation string... could you post your test string as its stored in mysql?
Grim...
DevNet Resident
Posts: 1445 Joined: Tue May 18, 2004 5:32 am
Location: London, UK
Post
by Grim... » Fri Aug 13, 2004 4:57 am
If you want to do it the simple way:
Code: Select all
<?php
$posttext = str_replace("[*code]", "<span class="code">", $posttext);
$posttext = str_replace("[/code*]", "</span>", $posttext);
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 13, 2004 5:08 am
this is involving php highlighting Grim, it's a tiny bit more complicated..