Jump to content

Need help with a parser (Smileys + bbcode)


Nolongerused3921

Recommended Posts

Whats a good general runtime for a parser that gets smileys (str_replace) and bbcode (regex) from a database, then parses data input into it... Say a 200 character string.

Also, is there anything I can do to speed this up?
[code=php:0]
$sql = "SELECT * FROM `". $this->bbcode_db ."`";
$db->query($sql,'bbcode_query');
$pattern = array();
$replacement = array();
while ($bbcode = $db->fetch_row('bbcode_query')) {
        array_push($pattern,$bbcode[pattern]);
array_push($replacement,$bbcode[replacement]);
        }
$data = preg_replace($pattern, $replacement, $data);
$sql = "SELECT * FROM `". $this->smiley_db ."`";
$db->query($sql,'smiley_query');
while ($smiley = $db->fetch_row('smiley_query')) {
        $data = str_replace($smiley[pattern], "<img src='".$this->rdir.$smiley[replacement]."' />", $data);
        }
[/code]

The code is pretty self explaintory. (My mysql functions do what you'd expect in those cases, and $rdir is just the real directory since I'm using mod_rewrite)
Right now I'm sitting at 0.01 seconds to do various site things (About 0.0038 seconds) so the parser itself, to parse the string
[code]
WOOOOOOOOooo[b]ooooo[/b]Oooooo[i]oooo[/i]TAH! :)
[/code]

With 7 entries in the bbcode table, and 1 in the smileys table, takes around 0.0062 seconds to parse that string... Which I, personally, feel is pretty slow. Theres got to be a way to speed this up while leaving it open enough to add new smileys/bbcode easily in the future.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.