UBBC Codes
Met dit script kan je teksten die ingevuld zijn met behulp van UBBC (United Bulletin Board Code) 'parsen' naar HTML. Het script is inclusief smileys en knoppen (gejat van YaBB) en javascripts om ze in het formulier toe te passen. Voordelen: 1) Teksten kunnen in UBBC in de database gezet worden, hierdoor is aanpassen erg makkelijk voor de gebruikers 2) Makkelijk werken voor HTML-noobs die wel opmaak in bericht willen hebben 3) Uitbreidbaar als je een klein beetje verstand van JavaScript, PHP en HTML hebt Het script is nog niet helemaal klaar. Voor de glow weet ik niet echt heel de code. Dus die doet het dan ook nog niet. ----- Update 20/08/2004 ----- Ik weet dat ik het eerder zou doen, maar ik heb hem nu echt aangepast. Ik was dit eigenlijk vergeten.. :D Wat ik heb veranderd: - De fout die Websmile aandroeg van die [b ] die niet afgesloten wordt. - Glow en Shadow doen het (IE-only), met dank aan VeeWee Het voorbeeld en de download zijn natuurlijk ook aangepast...
<?php
/* Ik kan hier niet alle scripts neerzetten, het 'script' bevat namelijk ook nog het één en ander aan HTML, plaatjes en JavaScript. Het is werkend te zien op http://fratsloos.nl/phphulp/UBBC/.
Verder staat niet het hele script van ubbc.php hier, want die is best groot. Het hele script staat natuurlijk wel op de download.
Als laatse heb ik ook niet de code van alle smilyes gedaan, maar slechts 3, toch allemaal hetzelfde...*/
// UBBC.PHP
// Enters V
$bericht = str_replace ("[br]","\n",$bericht);
$bericht = str_replace ("\n","<br>",$bericht);
// Code V
$bericht = str_replace ("[code]","<b>Code:</b><br /><table bgcolor=\"#000000\" cellspacing=\"1\" width=\"90%\"><tr><td><table cellpadding=2 cellspacing=\"0\" bgcolor=\"#FFFFFF\" width=\"100%\"><tr><td><font face=Courier size=\"1\" color=\"#000000\">", $bericht);
$bericht = str_replace ("[/code]", "</font></td></tr></table></td></tr></table>", $bericht);
// Vet, schuin, etc V
$bericht = preg_replace("/\[b\](.+?)\[\/b\]/is",'<strong>\1</strong>', $bericht);
$bericht = preg_replace("/\[i\](.+?)\[\/i\]/is",'<em>\1</em>', $bericht);
$bericht = preg_replace("/\[u\](.+?)\[\/u\]/is",'<u>\1</u>', $bericht);
$bericht = preg_replace("/\[s\](.+?)\[\/s\]/is",'<s>\1</s>', $bericht);
// Marquee
$bericht = str_replace ("[move]", "<div align=\"center\"><marquee width=\"90%\">", $bericht);
$bericht = str_replace ("[/move]", "</marquee></div>", $bericht);
// Color, font & size V
$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);
// Plaatje toevoegen V
$bericht = preg_replace("/\[img\](.*?)\[\/img\]/si", "<img src=\"\\1\" border=\"0\">",$bericht);
// Diversen V
$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 ("{{","[",$bericht);
$bericht = str_replace ("}}","]",$bericht);
// Horizontale lijn V
$bericht = str_replace ("[hr]","<hr color=\"#000000\" noshade />",$bericht);
// Lijst V
$bericht = str_replace ("[list]","<ul>",$bericht);
$bericht = str_replace ("[*]","<li>",$bericht);
$bericht = str_replace ("[/list]","</li></ul>",$bericht);
// Tabel V
$bericht = str_replace ("[table]","<table class=\"main\">",$bericht);
$bericht = str_replace ("[/table]","</table>",$bericht);
$bericht = str_replace ("[tr]","<tr>",$bericht);
$bericht = str_replace ("[/tr]","</tr>",$bericht);
$bericht = str_replace ("[td]","<td>",$bericht);
$bericht = str_replace ("[/td]","</td>",$bericht);
// Smiley's V
// Roll Eyes
$bericht = str_replace ("::)","<img src=\"img/ubbc/rolleyes.gif\" width=\"15\" height=\"15\" border=\"0\">",$bericht);
$bericht = str_replace ("[rolleyes]","<img src=\"img/ubbc/rolleyes.gif\" width=\"15\" height=\"15\" border=\"0\">",$bericht);
$bericht = str_replace ("::-)","<img src=\"img/ubbc/rolleyes.gif\" width=\"15\" height=\"15\" border=\"0\">",$bericht);
// Smile
$bericht = str_replace (":)","<img src=\"img/ubbc/smiley.gif\" width=\"15\" height=\"15\" border=\"0\">",$bericht);
$bericht = str_replace ("[smile]","<img src=\"img/ubbc/smiley.gif\" width=\"15\" height=\"15\" border=\"0\">",$bericht);
$bericht = str_replace (":-)","<img src=\"img/ubbc/smiley.gif\" width=\"15\" height=\"15\" border=\"0\">",$bericht);
// Wink
$bericht = str_replace (";)","<img src=\"img/ubbc/wink.gif\" width=\"15\" height=\"15\" border=\"0\">",$bericht);
$bericht = str_replace ("[wink]","<img src=\"img/ubbc/wink.gif\" width=\"15\" height=\"15\" border=\"0\">",$bericht);
$bericht = str_replace (";-)","<img src=\"img/ubbc/wink.gif\" width=\"15\" height=\"15\" border=\"0\">",$bericht);
?>
Reacties
0