Page 1 of 1

Analysing bbcode-like code

Posted: Mon Jan 19, 2009 2:50 pm
by zenhop
Hello,
Here is a code in a home-made language, created to be used as a template.
My template parser is working fine, except for the resources it uses.
Here is how it works:
It load the template file, and create a "map" locating the tags with many details, allowing the rest of the template parser to access easily the tag doing replaces, analysis, and everything needed.
But creating this map is taking a lot of resources since i'm not using any regex.

Here is an example of the code:

Code: Select all

 
    <fb:message title="Hello">world</fb:message>
    <fb:message title="another message" message="another content" />
    <fb:box title="this is the box's title" width="80%">
        box's content
        <fb:message title="hello">
            a message in a box
        </fb:message>
    </fb:box>
 
And here is the map generated, output via print_r():

Code: Select all

 
Array
(
    [0] => Array
        (
            [name] => message
            [args] => Array
                (
                    [title] => Hello
                )
 
            [str_args] => title="Hello"
            [start] => 124
            [end] => 150
            [len] => 26
            [str] => <fb:message title="Hello">
            [isSingleTag] => 0
            [type] => start
        )
 
    [1] => Array
        (
            [name] => message
            [args] => Array
                (
                )
 
            [str_args] => 
            [start] => 155
            [end] => 168
            [len] => 13
            [str] => </fb:message>
            [isSingleTag] => 0
            [type] => end
        )
 
    [2] => Array
        (
            [name] => message
            [args] => Array
                (
                    [title] => another message
                    [message] => another content
                )
 
            [str_args] => title="another message" message="another content" /
            [start] => 174
            [end] => 238
            [len] => 64
            [str] => <fb:message title="another message" message="another content" />
            [isSingleTag] => 1
            [type] => start
        )
 
    [3] => Array
        (
            [name] => message
            [original_name] => message
            [args] => Array
                (
                )
 
            [str_args] => 
            [start] => 238
            [end] => 238
            [len] => 0
            [str] => 
            [isSingleTag] => 1
            [type] => end
        )
 
    [4] => Array
        (
            [name] => box
            [args] => Array
                (
                    [title] => this is the box's title
                    [width] => 80%
                )
 
            [str_args] => title="this is the box's title" width="80%"
            [start] => 244
            [end] => 296
            [len] => 52
            [str] => <fb:box title="this is the box's title" width="80%">
            [isSingleTag] => 0
            [type] => start
        )
 
    [5] => Array
        (
            [name] => message
            [args] => Array
                (
                    [title] => hello
                )
 
            [str_args] => title="hello"
            [start] => 323
            [end] => 349
            [len] => 26
            [str] => <fb:message title="hello">
            [isSingleTag] => 0
            [type] => start
        )
 
    [6] => Array
        (
            [name] => message
            [args] => Array
                (
                )
 
            [str_args] => 
            [start] => 382
            [end] => 395
            [len] => 13
            [str] => </fb:message>
 
            [isSingleTag] => 0
            [type] => end
        )
 
    [7] => Array
        (
            [name] => box
            [args] => Array
                (
                )
 
            [str_args] => 
            [start] => 401
            [end] => 410
            [len] => 9
            [str] => </fb:box>
            [isSingleTag] => 0
            [type] => end
        )
)
 
QUestion:
How can I create this kind of "map" in an array with regex?

Re: Analysing bbcode-like code

Posted: Mon Jan 19, 2009 3:18 pm
by VladSun
I think regexp system will be too complicated.
Try this: http://www.google.com/search?ie=UTF-8&o ... php+bbcode
;)

Re: Analysing bbcode-like code

Posted: Mon Jan 19, 2009 3:32 pm
by Eran
This is facebook-markup language, not BBcode. http://wiki.developers.facebook.com/index.php/FBML

Re: Analysing bbcode-like code

Posted: Mon Jan 19, 2009 3:36 pm
by zenhop
the php native bbcode support don't support this format.
And I don't find any class doing that.
If I can't get this tag map, I'd just like to be able to at least detect the tags and send them to a home-mmade function.
Would that be possible?

like sending all the <fb:NAME ARG="VALUE"></fb:NAME> to a function? like using an ereg_replace or anything?


And about the Facebook markup language, yes, I took the structure as an example. But this is not the same use, and has nothing to do with FBML.

Re: Analysing bbcode-like code

Posted: Mon Jan 19, 2009 3:37 pm
by VladSun
Yes, I know it, but in PHP bbcode parser libraries one can define any bbcode tag (a new one) he needs. So, I suppose that it could be a quick solution.
http://bg.php.net/manual/bg/function.bb ... lement.php