FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


BB Codes





DanielXP
Ok i have the following BB Codes

Code:
<?php


function parseubb($bericht,$quote_color){
   $bericht = str_replace ("[br]", "<br>", $bericht);
   $bericht = str_replace ("[b]", "<b>", $bericht); // [b ] zonder spatie
   $bericht = str_replace ("[i]", "<i>", $bericht); // [i ] zonder spatie
   $bericht = str_replace ("[u]", "<u>", $bericht); // [u ] zonder spatie
   $bericht = str_replace ("[s]", "<s>", $bericht);
   $bericht = str_replace ("[/b]", "</b>", $bericht); // [/b ] zonder spatie
   $bericht = str_replace ("[/i]", "</i>", $bericht); // [/i ] zonder spatie
   $bericht = str_replace ("[/u]", "</u>", $bericht); // [/u ] zonder spatie
   $bericht = str_replace ("[/s]", "</s>", $bericht);
   $bericht = str_replace ("[move]", "<div align=\"center\"><marquee width=\"90%\">", $bericht);
   $bericht = str_replace ("[/move]", "</marquee></div>", $bericht);
   $bericht = preg_replace ("/\[glow(.*)\](.*)\[\/glow\]/",">> GLOW <<",$bericht);
   $bericht = preg_replace ("[/glow]","", $bericht);
   $bericht = preg_replace ("/\[shadow(.*)\](.*)\[\/shadow\]/", ">> SHADOW <<", $bericht);
   $bericht = preg_replace ("#\[color=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]#si", "<font color=\"\\1\">\\2</font>", $bericht);
   $bericht = preg_replace ("/\[font=(.*)\](.*)\[\/font\]/", "<font face=\"$1\">$2</font>", $bericht);
   $bericht = preg_replace ("/\[size=(.*)\](.*)\[\/size\]/", "<font size=\"$1\">$2</font>", $bericht);
   $bericht = preg_replace("/\[img\](.*?)\[\/img\]/si", "<img src=\"\\1\" border=\"0\">",$bericht);
   $bericht = str_replace ("[tt]", "<tt>", $bericht);
   $bericht = str_replace ("[/tt]", "</tt>", $bericht);
   $bericht = str_replace ("[left]", "<div align=left>", $bericht);
   $bericht = str_replace ("[/left]", "</div>", $bericht);
   $bericht = str_replace ("[center]", "<div align=\"center\">", $bericht);
   $bericht = str_replace ("[/center]", "</div>", $bericht);
   $bericht = str_replace ("[right]", "<div align=\"right\">", $bericht);
   $bericht = str_replace ("[/right]", "</div>", $bericht);
   $bericht = str_replace ("[sub]", "<sub>", $bericht);
   $bericht = str_replace ("[/sub]", "</sub>", $bericht);
   $bericht = str_replace ("[sup]", "<sup>", $bericht);
   $bericht = str_replace ("[/sup]", "</sup>", $bericht);
   $bericht = str_replace ("[fixed]", "<font face=\"Courier New\">", $bericht);
   $bericht = str_replace ("[/fixed]", "</font>", $bericht);
   $bericht = str_replace ("[[","{{",$bericht);
   $bericht = str_replace ("]]","}}",$bericht);
   $bericht = str_replace ("|","|",$bericht);
   $bericht = str_replace ("[pre]","<pre>",$bericht);
   $bericht = str_replace ("[/pre]","</pre>",$bericht);
   $bericht = str_replace ("[php]","<fieldset><table border='0' width='100%'><tr><td border='0' style='border-bottom: 1px dotted #808080;'><b>PHP:</b></td></tr><tr><td>",$bericht);
   $bericht = str_replace ("[/php]","</td></tr></table></fieldset>",$bericht);
   $bericht = str_replace ("[code]","<fieldset><table border='0' width='100%'><tr><td border='0' style='border-bottom: 1px dotted #808080;'><b>Code:</b></td></tr><tr><td>",$bericht);
   $bericht = str_replace ("[/code]","</td></tr></table></fieldset>",$bericht);
   $bericht = str_replace ("{{","[",$bericht);
   $bericht = str_replace ("}}","]",$bericht);
   $bericht = str_replace ("[hr]","<hr color=\"#FFFFFF\" noshade />",$bericht);
   $bericht = eregi_replace("\\[email=([^\\[]*)\\]([^\\[]*)\\[/email\\]", "<a href=\"mailto:\\1\">\\2</a>",$bericht); 
   $bericht = eregi_replace("\\[url=([^\\[]*)\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=_blank>\\2</a>",$bericht);
   $bericht = preg_replace("/\[url\](.*?)\[\/url\]/si", "<a href=\"\\1\" target=_blank>\\1</a>",$bericht);
   $bericht = preg_replace("/\[email\](.*?)\[\/email\]/si", "<a href=\"mailto:\\1\">\\1</a>",$bericht);
   $bericht = preg_replace ("#\[ftp\]([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\[/ftp\]#", "<a href=\"ftp://\\1\\2\" target=\"_blank\">\\2</a>", $bericht);
   $bericht = preg_replace ("#\[ftp\]([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\[/ftp\]#", "<a href=\"ftp://\\1\" target=\"_blank\">\\1</a>", $bericht);
   $bericht = preg_replace ("#\[ftp=([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\](.*?)\[/ftp\]#", "<a href=\"ftp://\\1\\2\" target=\"_blank\">\\2</a>", $bericht);
   $bericht = preg_replace ("#\[ftp=([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\](.*?)\[/ftp\]#", "<a href=\"ftp://\\1\" target=\"_blank\">\\2</a>", $bericht); 
 
  $bericht = preg_replace("/\[quote=(.+?)\](.+?)\[\/quote\]/is", '<br><table width="100%" cellspacing="0" cellpadding="0"><tr><td width="5%">&nbsp;</td><td>Quote:</td></tr><tr><td width="5%">&nbsp;</td><td bgcolor="#D8E6FF" class="border">$1<br>$2</td></tr></table><br>', $bericht);

   $bericht = str_replace ("[list]","<ul>",$bericht);
   $bericht = str_replace ("[*]","<li>",$bericht);
   $bericht = str_replace ("[/list]","</li></ul>",$bericht);

   $bericht = str_replace ("::D","<img border='0' src='images/biggrin.gif'>",$bericht);
   $bericht = str_replace (":)","<img border='0' src='images/smile.gif'>",$bericht);
   $bericht = str_replace ("8)","<img border='0' src='images/cool.gif'>",$bericht);
   $bericht = str_replace (":S","<img border='0' src='images/confused.gif'>",$bericht);
   $bericht = str_replace (":arrow:","<img border='0' src='images/arrow.gif'>",$bericht);
   $bericht = str_replace (":cry:","<img border='0' src='images/cry.gif'>",$bericht);
   $bericht = str_replace (":!:","<img border='0' src='images/exclaim.gif'>",$bericht);
   $bericht = str_replace (":lol:","<img border='0' src='images/lol.gif'>",$bericht);
   $bericht = str_replace ("&gt;(","<img border='0' src='images/mad.gif'>",$bericht);
   $bericht = str_replace (":|","<img border='0' src='images/neutral.gif'>",$bericht);
   $bericht = str_replace (":?:","<img border='0' src='images/question.gif'>",$bericht);
   $bericht = str_replace (":P","<img border='0' src='images/razz.gif'>",$bericht);
   $bericht = str_replace (":(","<img border='0' src='images/sad.gif'>",$bericht);
   $bericht = str_replace (":O","<img border='0' src='images/surprised.gif'>",$bericht);
   $bericht = str_replace (":roll:","<img border='0' src='images/rolleye.gif'>",$bericht);

return $bericht;
}
?>


I want to add a string highlighter on the [*code] and [*php]

i have been trying for ages but can not do this so please can some one try and put it in for me please.

Thanks
Maryndor
That [php] and [code] in there is not working, or?!
DanielXP
DanielXP wrote:
I want to add a string highlighter on the [*code] and [*php]
DanielXP
Can no one help i need it quick

when its done my site will be sold thats why i need it done quick
hexkid
DanielXP wrote:
I want to add a string highlighter on the [*code] and [*php]


For PHP code wouldn't highlight_string() suit you?

For the [*code], what do you really mean?
Basic? Pascal? C? C++? C#? RPG? Lisp? FORTRAN? Prolog? Smalltalk? APL? Intel 80x86 Assembler? SQL? ABAP? Forth? Python? M4? XSLT? ... ... ... ...
DanielXP
Just use highlight_string() on both.

I tryed this but it did not work it made all the page writing really small.
hexkid
DanielXP wrote:
I tryed this but it did not work it made all the page writing really small.


It works for me. I've even made a test page Smile
DanielXP
what using my bb code script?

whats the code for my bb code script with it in then?
hexkid
DanielXP wrote:
what using my bb code script?

whats the code for my bb code script with it in then?


I believe you cannot do it with simple str_replace() or preg_replace() calls.
You need to use a parser (either make your own or search the web).
DanielXP
I tryed making me own one this is it

Code:
<?php

function parseubb($text)
{

$pattern[] = '/\[b\](.*?)\[\/b\]/';
$replace[] = '<span style="font-weight:bold">$1</span>';

$pattern[] = '/\[i\](.*?)\[\/i\]/';
$replace[] = '<span style="font-style:italic">$1</span>';

$pattern[] = '/\[u\](.*?)\[\/u\]/';
$replace[] = '<span style="text-decoration:underline">$1</span>';

$pattern[] = '/\[color=(.*?)\](.*?)\[\/color\]/';
$replace[] = '<span style="color: $1">$2</span>';

$pattern[] = '/\[url=(.*?)\](.*?)\[\/url\]/';
$replace[] = '<a href="$1">$2</a>';

$pattern[] = '/\[url\](.*?)\[\/url\]/';
$replace[] = '<a href="$1">$1</a>';

$pattern[] = '/\[img\](.*?)\[\/img\]/';
$replace[] = '<img src="$1">';

$pattern[] = '/\[b\](.*?)\[\/b\]/';
$replace[] = '<b>$1</b>';

$pattern[] = '/\[php\](.*?)\[\/php\]/';
$replace[] = '<fieldset><table border="0" width="100%"><tr><td border="0" style="border-bottom: 1px dotted #808080;"><b>PHP:</b></td></tr><tr><td>highlight_string($1)</td></tr></table></fieldset>';

$text = preg_replace($pattern, $replace, $text);
return $text;
}

?>


The PHP bbcode don't work it just displays the normal text.[/code]
hexkid
DanielXP wrote:
The PHP bbcode don't work it just displays the normal text.


You might want to add the 's' (and 'i') modifier to all your regular expressions, and also the 'e' modifier to the [php] regexp.
Code:
  $pattern[] = '/\[php\](.*?)\[\/php\]/se';
  $replace[] = '\'<fieldset><table border="0" width="100%"><tr><td border="0" style="border-bottom: 1px dotted #808080;"><b>PHP:</b></td></tr><tr><td>\'.highlight_string(\'$1\', true).\'</td></tr></table></fieldset>\'';
DanielXP
Still not higlighting

u think it might be coz im doing htmlspechars?
hexkid
It works for me.
test page updated Smile
DanielXP
yer but if u read mine comes from a db and it removes the htmlspecialchars

so mine don't come out with < and >'s
hexkid
DanielXP wrote:
yer but if u read mine comes from a db and it removes the htmlspecialchars

so mine don't come out with < and >'s


So, you shouldn't remove the htmlspecialchars from inside [*php].
That's one of the reasons why doing what you want with preg_replace() isn't the best idea ... I continue to say you need to build/use a parser.
DanielXP
i can't bulid one im rubbish
Related topics
FTP Codes
UBB Code / Smiley Parsing
BB Codes
BB Codes
Was there any point to sending men to the moon?
phpBB allowing HTML in sigs?
BB Code :|
PM Logout
How to realize "BB-Code"
UBB-codes voor op website
Moderators && Payed Option?
Can we ban "lulzy" English?
bb code help - regex
BB Codes usage is a little weird :S
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.