![]() |
|
#1
|
||||
|
||||
BBcode clonehi, I've been trying to make a clone of the BB Code for my forum (I always try to make my own stuff you see) and... well this is the function I made :
PHP Code:
now I want the program to check if a tag has been closed and if not, it closes it itself. I thought I could substract the numbers of open tags to the number of closed tags but the function "eregi" (or "ereg", though it's case sensitive) just tells if there's an occurence and not how many please help me!! i wanted to create the "quote", "code" and "highlight" tags but if the user doesnt close these it could ruin the appearance of my site \o/ |
|
#2
|
||||
|
||||
Re: BBcode cloneThe bbcode class I wrote for www.gidnetwork.com is quite efficient in that it only goes through a string once.
I am not a c or c++ programmer, but I assume each call to eregi_replace() or preg_replace() triggers a scan of the entire string, which I think is completely unnecessary. This is why I wrote my own version which does nearly everything in just one pass. I don't want to paste the entire class here but I will go through the script today, extract the relevant bits and post a much "lighter" version of it as soon as possible. If it does nothing else, it will encourage you to write yours again and to do it quite differently. ... and yes, it handles (auto-closes) opened bbcode tags at the end of the string. __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#3
|
||||
|
||||
Re: BBcode cloneAs promised, here is the basic (lite) version of my bbcode class:
PHP Code:
If you look closely at the method: parse( $str ), you'll see that it translates all the bbcodes (in a string) in a single pass. If you saved this example code to a file, say, GIDBBCode.inc.php, you would use it like this on a regular script/web page: PHP Code:
Again, this is an extract from my original bbcode handler class, so I may have introduced some bugs in the process. __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#4
|
|||
|
|||
Re: BBcode cloneJDS you are soo clever
|
|
#5
|
|||
|
|||
Re: BBcode cloneJDS:
In your regular version, did you by any chance create a PHP parser? |
|
#6
|
||||
|
||||
Re: BBcode cloneIf you mean "php syntax highlighter" by "PHP parser", then yes, I did. See the code example here. Why?
Besides PHP, we also have custom syntax highlighters for other popular languages like C++, C#, Java, python, VB and even CSS markup. __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#7
|
|||
|
|||
Re: BBcode cloneThat link that you gave me does not have any example for parsing php.
Well, I am writing my own forum script, and I would like a PHP parser, but I cannot find ANYTHING that works. I think that for some reason, the PHP tags go through the server and do not show anything BEFORE I can even parse them. |
|
#8
|
||||
|
||||
Re: BBcode cloneQuote:
You could take a look at this script. It is released under the GPL for your parsing pleasure. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#9
|
|||
|
|||
Re: BBcode cloneI was looking for a [php] tag parser, but this does help with other tags! Thanks a bunch...
|
|
#10
|
||||
|
||||
Re: BBcode clonethanks for the code JayDeeEss, and sorry for not responding earlier! ^^;
and btw, there are indeed some bugs in your class >_o just one, to be precise, you didn't initialize the $markup variable. But the rest is pure gold, thanks a lot!! |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: BBCode - the [quote] tag | JdS | PHP Code Library | 0 | 05-May-2005 06:05 |
| [Discussion] New HTML BBCode. | jrobbio | Web Design Forum | 8 | 14-Oct-2004 14:20 |
| Php bbcode issue | Caged | MySQL / PHP Forum | 3 | 06-Aug-2003 18:55 |
| GIDForums enables New [CSS] bbcode. | admin | GIDForums™ | 0 | 01-Jun-2003 23:57 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The