Jump to content


Php parser structure help

  • Please log in to reply
1 reply to this topic

#1 ifreborn

  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 14 June 2006 - 12:56 PM

need a little help understanding the structure of this parser and parsers in general.

I know how the function works and the array what i dont get is what:

function bbcode($string){

$string = nl2br(htmlspecialchars($string));

$patterns = array(

                                    '`\[url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]`si',
                                    '`\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si',
                                    '`\[url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]`si',


$replaces =  array(

                                    '<span style="border-bottom: 1px dotted">\\1</span>',
                                    '<span style="color:#\1;">\2</span>',
                                    '<a href="mailto:\1">\1</a>',
                                    '<img src="\1" alt="" style="border:0px;" />',
                                    '<a href="\1\2">\6</a>',
                                    '<a href="\1\2">\1\2</a>',
                                    '<a href="http://\1">\1</a>',
                                    '<object width="\1" height="\2"><param name="movie" value="\3" /><embed src="\3" width="\1" height="\2"></embed></object>',
                                    '<strong>Quote:</strong><div style="margin:0px 10px;padding:5px;background-color:#F7F7F7;border:1px dotted #CCCCCC;width:80%;"><em>\1</em></div>',


$string = preg_replace($patterns, $replaces , $string);

return $string;

#2 joquius

  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 14 June 2006 - 01:44 PM

that's regular expressions.
In this case:
(.+?) means "match more than one char" (between the previous and following matches
([0-9]{6})\](.+?) means match 6 instances of numbers 0-9, one ] char and then the previous .+?

for this stuff you should look at the regular expressions tutorial

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users