• Implementing phpBBcode into my site?
    19 replies, posted
I tried googling and found this phpBBcode and from what I understood it's just a script you can implement into your site. But it seems that all the sites have the links removed or something. They don't have any information where to download or buy or whatever.
BBcode is basically just a common set of commands for text formatting. You can use it as you wish. There is no certain script you have to use, you can download any and fit it to your needs or maybe even write your own. Basically you will need two different parts: A parser which will parse the formatting commands and convert them into HTML so that someone actually sees [b]Hello World[/b] instead of [noparse][b]Hello World[/b][/noparse]. Those are often PHP scripts you can just call like $output = parsebb($input), that is, after including it and maybe setting some parameters. There might also be some Javascript scripts for that if you don't have PHP on your host or don't know anything about it. Negative side effects would be that the user might actually see the tags while loading the page until the script parses them. Then, if you want to, you need an editor. The thing, where you actually write your contents in and then format them. There are loads of those out there, you need a fair bit of JS knowledge to properly use and customize them. If you're the only one making the input and you can't be assed to play around with those editors you could always just write the tags yourself.
I see, well, I guess I thought normal HTML commands don't work with stripslashes and mysql_escape_real_string and what not. Just tested 'em out and everything works just fine. Thanks for the info. :)
I can show you how to do some simple BBCode that I implemented on [url]www.gmfiles.com[/url] [php] public function parseDescriptionText($descriptionText){ $descriptionText = htmlentities(stripslashes($descriptionText)); $in=array( '`((?:https?|ftp)://\S+[[:alnum:]]/?)`si', '`((?<!//)(www\.\S+[[:alnum:]]/?))`si', "/\[b\](.+?)\[\/b]/", "/\[u\](.+?)\[\/u]/", "/\[i\](.+?)\[\/i]/" ); $out=array( '<a href="$1">$1</a>', '<a href="http://$1">$1</a>', "<strong>$1</strong>", "<u>$1</u>", "<em>$1</em>" ); return preg_replace($in, $out, $descriptionText); } [/php]
Hmm thanks for the code, but I'm not really sure how to implement it. I put it in a separate file and link it with <script....></script> but it doesn't seem to work. What am I suppose to edit beside that?
That's PHP. [img_thumb]http://th00.deviantart.net/fs24/300W/i/2008/022/f/1/facepalm_gif_by_thatweirdo7.jpg[/img_thumb]
I lol'd. Sorry, been using Javascript a lot lately, got them mixed up :D And they are very similar! EDIT: Well even so, I'm not sure where to place it? No matter where I put it it says [code]Parse error: syntax error, unexpected T_PUBLIC in /home/wwwcremb/public_html/system/index.php on line XX[/code] EDIT2: Removing the "public" part of it fixed it...
No?
Yes! EDIT: Everything's working fine, thanks for the bashing and thanks for the help. I appreciate both.
That's because it was part of one of my classes on gmfiles.com. I just copy pasted.
We're you talking about the PhpBB forum system or BBcode?
BBCode itself.
Chunks of my modified bbcode parser, this uses CSS instead of HTML tags. (yes it's perl, but feel free to adapt it to your needs): [code] #BBCode Bold $$text =~ s!\[b\](.+?)\[/b\]!"<span style='font-weight:bold;'>$1</span>"!egi; #BBCode Italic $$text =~ s!\[i\](.+?)\[/i\]!"<span style='font-style:italic;'>$1</span>"!egi; #BBCode StrikeThrough $$text =~ s!\[s\](.+?)\[/s\]!"<span style='text-decoration:line-through;'>$1</span>"!egi; #BBCode Highlight $$text =~ s!\[highlight\](.+?)\[/highlight\]!"<span style='color:red;'>$1</span>"!egi; #BBCode Underline $$text =~ s!\[u\](.+?)\[/u\]!"<span style='text-decoration:underline;'>$1</span>"!egi; #BBCode Blink $$text =~ s!\[blink\](.+?)\[/blink\]!"<span style='text-decoration:blink;'>$1</span>"!egi; #BBCode Color $$text =~ s!\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6}|rgb\(\d{1,3}\,\d{1,3}\,\d{1,3}\))\](.+?)\[/color\]!"<span style='color:$1;'>$2</span>"!egi; #BBCode Font $$text =~ s!\[font=([a-zA-Z]*)\](.+?)\[/font\]!"<span style='font-family:$1;'>$2</span>"!egi; #BBCode Center $$text =~ s!\[center\](.+?)\[/center\]!"<div align='center'>$1</div>"!egi; #BBCode Left $$text =~ s!\[left\](.+?)\[/left\]!"<div align='left'>$1</div>"!egi; #BBCode Right $$text =~ s!\[right\](.+?)\[/right\]!"<div align='right'>$1</div>"!egi; #BBCode Size Special Crap $$text =~ s!\[size=([0-9]+?)\](.+?)\[/size\]!my $sizeclmp = $m->min($1, 90);"<span style='fontsize:" . $sizeclmp . "px;'>$2</span>"!egi; [/code]
[QUOTE=Morphology53;21284017]Chunks of my modified bbcode parser, this uses CSS instead of HTML tags. (yes it's perl, but feel free to adapt it to your needs): [code] #BBCode Bold $$text =~ s!\[b\](.+?)\[/b\]!"<span style='font-weight:bold;'>$1</span>"!egi; #BBCode Italic $$text =~ s!\[i\](.+?)\[/i\]!"<span style='font-style:italic;'>$1</span>"!egi; #BBCode StrikeThrough $$text =~ s!\[s\](.+?)\[/s\]!"<span style='text-decoration:line-through;'>$1</span>"!egi; #BBCode Highlight $$text =~ s!\[highlight\](.+?)\[/highlight\]!"<span style='color:red;'>$1</span>"!egi; #BBCode Underline $$text =~ s!\[u\](.+?)\[/u\]!"<span style='text-decoration:underline;'>$1</span>"!egi; #BBCode Blink $$text =~ s!\[blink\](.+?)\[/blink\]!"<span style='text-decoration:blink;'>$1</span>"!egi; #BBCode Color $$text =~ s!\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6}|rgb\(\d{1,3}\,\d{1,3}\,\d{1,3}\))\](.+?)\[/color\]!"<span style='color:$1;'>$2</span>"!egi; #BBCode Font $$text =~ s!\[font=([a-zA-Z]*)\](.+?)\[/font\]!"<span style='font-family:$1;'>$2</span>"!egi; #BBCode Center $$text =~ s!\[center\](.+?)\[/center\]!"<div align='center'>$1</div>"!egi; #BBCode Left $$text =~ s!\[left\](.+?)\[/left\]!"<div align='left'>$1</div>"!egi; #BBCode Right $$text =~ s!\[right\](.+?)\[/right\]!"<div align='right'>$1</div>"!egi; #BBCode Size Special Crap $$text =~ s!\[size=([0-9]+?)\](.+?)\[/size\]!my $sizeclmp = $m->min($1, 90);"<span style='fontsize:" . $sizeclmp . "px;'>$2</span>"!egi; [/code][/QUOTE] That's crap. BBCode is not a regular language and should not be parsed like a regular language (using regular expressions.) You should be using a state machine parser instead. [url=http://github.com/charliesome/bbsharp]Here's mine[/url]. It's in C#, but it should be easy to adapt to PHP (it's just logic after all)
[QUOTE=turb_;21284438]That's crap. BBCode is not a regular language and should not be parsed like a regular language (using regular expressions.) You should be using a state machine parser instead. [url=http://github.com/charliesome/bbsharp]Here's mine[/url]. It's in C#, but it should be easy to adapt to PHP (it's just logic after all)[/QUOTE] Even so, why on earth would I write an actual parser when a couple 1 line regexs would do the exact same thing? I'd rather keep things as simple as possible, that way I have more time to spend drinking.
[QUOTE=turb_;21284438]That's crap. BBCode is not a regular language and should not be parsed like a regular language (using regular expressions.) [/QUOTE] Is there any specific reason besides being all smug and feeling superior because you just wrote a bunch of unnecessary code when you do so? It's more code and the exact same outcome, performance isn't even an argument for a small bbcode parser.
[QUOTE=Tu154M;21285460]Is there any specific reason besides being all smug and feeling superior because you just wrote a bunch of unnecessary code when you do so?[/QUOTE] Feeling smug and superior is a large part, but security is also a factor. Because BBCode is not a regular language, regexes may be able to do good job 95% of the time, but they will always fail in some way, usually to do with XSS attacks. By parsing BBCode into a tree and making the computer 'understand' the BBCode, rather than just applying some transformations to a string, you can much more easily keep things nice and secure. Jeff Atwood and Joel Spolsky actually discussed this very regex vs. parser issue on the Stack Overflow podcast a few weeks ago (although they were talking about Markdown, the point still stands)
[QUOTE=turb_;21285675]Feeling smug and superior is a large part, but security is also a factor. Because BBCode is not a regular language, regexes may be able to do good job 95% of the time, but they will always fail in some way, usually to do with XSS attacks. By parsing BBCode into a tree and making the computer 'understand' the BBCode, rather than just applying some transformations to a string, you can much more easily keep things nice and secure. Jeff Atwood and Joel Spolsky actually discussed this very regex vs. parser issue on the Stack Overflow podcast a few weeks ago (although they were talking about Markdown, the point still stands)[/QUOTE] So are you going to give us an example of how one of those regexes will open a portal to a XSS attack, or do you think that we will take your word for it and implement a full-blown parser because you said bad things could happen otherwise? I don't have a problem being told that my ideas suck, but at the same time I need a bit more then "These guys said it's bad", and "95% of the time, it's cool".
[url]http://kore-nordmann.de/blog/do_NOT_parse_using_regexp.html[/url]
[QUOTE=Darkimmortal;21289007][url]http://kore-nordmann.de/blog/do_NOT_parse_using_regexp.html[/url][/QUOTE] Good link, explains it better than I can, also: [quote]It is impossible to parse a language like BBCode with regular expressions because you only may parse regular languages using regular expressions.[/quote] I told you so :v:
Sorry, you need to Log In to post a reply to this thread.