473,978 Members | 7,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BBCode/HTML filters

TheServant
1,168 Recognized Expert Top Contributor
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 2269
Markus
6,050 Recognized Expert Expert
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 Recognized Expert Expert
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 Recognized Expert Expert
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 Recognized Expert Expert
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 Recognized Expert Top Contributor
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 Recognized Expert Expert
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 Recognized Expert Expert
Yea. Regex can be very annoying. Too bad they made them so damn useful :)

Happy coding! 8)
Jun 2 '08 #8
TheServant
1,168 Recognized Expert Top Contributor
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 Recognized Expert Expert
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.inf o. Lots of useful info there.
Jun 3 '08 #10

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

Similar topics

1
3817
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 particular the encoder/decoder for the emoticons & bbcode and any examples of form layouts for textual input with all the appropriate '' and emoticon buttons?. Ta in advance, Dave
12
2448
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 <!V>p<!U>o<!P>ss<!F>e<!L>s<!U> <!S>a <!J>de<!S>gr<!T>ee <!W>a<!K>r<!I>e<!V> l<!O>o<!D>o<!W>k<!C>ed <!J>upo<!R>n<!K> a<!U>s<!G> <!X>th<!O>e <!E>elit<!U>e<!N><BR> <!T> If yo<!Q>u <!B>ha<!C>ve<!Y> a<!S> d<!Q>eg<!E>r<!Y>ee<!E>, yo<!F>u<!N> a<!Z>re<! M>...
1
1670
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 poor englist)
0
1046
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... http://www.willmcgugan.com/2007/03/10/bbcode-python-module/ Will McGugan
8
5354
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 my own, but my vbscript/COM skills are a little rusty since I work with C# and .Net for almost the last decade. does anyone know of something or has a snippet of code in his/her bottom drawer? any hint/help is greatly appreciated.
3
2041
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 enabling it which can allow any user that does not know the bbocde mess up the page? Thanks!
1
3889
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? Thanx
8
1849
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 the BBCode parser should be configured. Is it to be configured by ourselves or will it be done by the hosting ISP. And will the tag be supported by BBCode?
2
3760
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 to be a .dll file located in the extensions folder in the php root directory, and there needs to be a line in the php.ini file that is uncommented that loads the .dll extension. But which .dll is it? Is it already in that folder, or do I need to...
0
10358
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10175
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11425
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10921
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8465
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7620
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4742
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3773
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.