473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

BBCode/HTML filters

TheServant
1,168 Expert 1GB
Another thread sparked an interest:
With using BBCode, do you have to install that package or is it the browser that recognises it? I would like to make my own for my website to let certain users edit the code (without needing to know html) and so I was just wondering where I should look. Most of the links refer to phpBB forums, but this will be using my own code on my site.

Alternatively, if this is not available, do any of you know a good free html filter (which is basically what BBCode is I believe)?
Jun 1 '08 #1
10 2229
Markus
6,050 Expert 4TB
Another thread sparked an interest:
With using BBCode, do you have to install that package or is it the browser that recognises it? I would like to make my own for my website to let certain users edit the code (without needing to know html) and so I was just wondering where I should look. Most of the links refer to phpBB forums, but this will be using my own code on my site.

Alternatively, if this is not available, do any of you know a good free html filter (which is basically what BBCode is I believe)?
You can install it, or create your own. It's nothing to do with the browser.

You just turn [b] text [/b] into <b> text </b> using regular expressions.

:)
Jun 1 '08 #2
Atli
5,058 Expert 4TB
It is very simple to implement the basic BBCode tags yourself, like Marcus mentioned.

You could simply use str_replace to replace the BBCode tags with their HTML counterparts.

For example, for bold and italic text:
Expand|Select|Wrap|Line Numbers
  1. $BBCodeTags = array("[b]", "[/b]", "[i]", "[/i]");
  2. $HTMLTags = array("<strong>", "</strong>", "<em>", "</em>");
  3. $out = str_replace($BBCodeTags, $HTMLTags, $in);
  4.  
Other, more complex tags may require regular expressions, like the [url] tags:
Expand|Select|Wrap|Line Numbers
  1. $regex = '#\[url\](.*?)\[\/url\]#is';
  2. $replace = '<a target="_blank" href="$1">$1</a>';
  3. $out = preg_replace($regex, $replace, $in);
  4.  
You get the point.

If your not up to that, there is a PEAR class and probably some free PHP classes available.
Jun 2 '08 #3
Markus
6,050 Expert 4TB
It is very simple to implement the basic BBCode tags yourself, like Marcus mentioned.
Markus with a k, my friend.

;]
Jun 2 '08 #4
Atli
5,058 Expert 4TB
Markus with a k, my friend.
Sorry mate... accidentally wrote it with a small M and then clicked the wrong item in the Firefox word-hint menu :P
Jun 2 '08 #5
TheServant
1,168 Expert 1GB
That's fantastic guys. I was going to do it that way, but I didn't know you could use str_replace with arrays! Anyway, that will be much easier. I need to practice with regex though, as somethings I want to do could be complex. But you have given me lots to work on thanks!
Jun 2 '08 #6
Markus
6,050 Expert 4TB
That's fantastic guys. I was going to do it that way, but I didn't know you could use str_replace with arrays! Anyway, that will be much easier. I need to practice with regex though, as somethings I want to do could be complex. But you have given me lots to work on thanks!
Regexps are awful! But necessary.

Keep on rockin'!
Jun 2 '08 #7
Atli
5,058 Expert 4TB
Yea. Regex can be very annoying. Too bad they made them so damn useful :)

Happy coding! 8)
Jun 2 '08 #8
TheServant
1,168 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. $regex = '#\[url\](.*?)\[\/url\]#is';
  2. $replace = '<a target="_blank" href="$1">$1</a>';
  3. $out = preg_replace($regex, $replace, $in);
  4.  
I am confused. looked at quite a few regex websites, but none are complete with knowledge. Do you guys have a recommended regex site with all the commands?

I have some questions about this:
Isn't the # indicating commenting?
What is the "is" on the end of line 2?

If I am asking the wrong questions, let me know a site and I will work it out because these more involved regex ones I have never spent any time on. Thanks again.
Jun 3 '08 #9
Atli
5,058 Expert 4TB
I have some questions about this:
Isn't the # indicating commenting?
What is the "is" on the end of line 2?
The # there marks the beginning and end of the regex itself.
The / char is typically used, but you can use other chars if you chose to do so. The # char is just a personal preference of mine.

The same regex could have been written like so and it would have made no difference.
Expand|Select|Wrap|Line Numbers
  1. /\[url\](.*?)\[\/url\]/is
The 'i' and 's' at the end are options.
The 'i' makes the search case-insensitive, while the 's' includes the new-line char in the dot-class, effectively making the search capable of spanning multiple lines.

Check out Regular-Expressions.info. Lots of useful info there.
Jun 3 '08 #10
TheServant
1,168 Expert 1GB
Thanks mate. I also found this one which I printed for further reference. Thought i should share it!
Jun 3 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dave Moore | last post by:
Hi All, I'd like enable visitors to my website to use bbcode and emoticons whilst entering text into a form. Are there any standard lumps of php/javascript I can use for this purpose?. In...
12
by: Mr. Clean | last post by:
As you may know, spammer use this technique to get by filters. <!H>It<!W> is<!N> <!K>a<!L> w<!Q>el<!Q>l <!X>k<!O>now<!B>n <!F>f<!G>a<!V>c<!O>t <!S>th<!B>at p<!R>eopl<!J>e<!G> <!Z>who...
1
by: 如履薄冰 | last post by:
BBcode reference: http://www.phpbb.com/phpBB/faq.php?mode=bbcode I want write a BBcode module in Python, but I'v not idea for this. Who can tell me about this arithmetic? ( I'm so sorry for my...
0
by: Will McGugan | last post by:
Hi, I have written a BBCode parsing module that may be of use to some people. It turns BBCode in to XHTML snippets. See the following page if you are interested... ...
8
by: Matthias S. | last post by:
hi there, i'm desperately looking for an HTML to BBCode (and vice versa) converter, either as a COM component or vbScript for use in an ASP (not .NET) web-application. i sure could write one on...
3
Ajm113
by: Ajm113 | last post by:
Hi, I created a forum and I made a secrete BBcode tag using this tutorial: <Link removed> How can I enable HTML using that code if I am using it on a script that gets rid of the html with out...
1
by: Toni | last post by:
Where can I find BBCode editor (editor for forums and blogs) for ASP.NET. I need editor like FreeTextBox (but BBCode, not HTML like FreeTextBox). I need source code or control. Where can I find it?...
8
by: raaman rai | last post by:
i am adding dynamic contents in my website. So i also want to have a news or announcements to be dynamically displayed. But for this i need to use BBCode. But in reference to this, i dont know how...
2
by: bgold12 | last post by:
I already posted this message, but it didn't work or something. So if this is a duplicate, ignore it. I just can't figure out how to install this extension. From what I understand, there needs...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.