Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views


Sign in to follow this  
Evil Steve


Yay, my Game Programming Gems 5 book arrived today. I'm happy.

I've got my site in a fairly reasonable state now. I'm parsing the BBC Technology, Slashdot or GameDev.Net RSS feeds (randomly selected) for a bit more substance on the page, I've got a very simple thumbnailing script for my Image Of The Day gallery, and I can read posts from my forum. The hardest part of it all was parsing the damn bbcode. Since I've never used regex before, I really didn't have a clue what I was doing. But I finally got it working, with help from Gyzmo, Pouya, and johnb. I can parse: url (both blah and blah.com), img, b, i, u, list (and
    1. ), quote, and code.
      The code is a bit... funky, but it works well enough for me. Here's what I have:

      $search = array(
      $replace = array(
      '"\\2" alt="Image"/>',
  • \\2
  • ',
    class="smalltext">\\2 wrote:

    $post = preg_replace($search,$replace,$row['post_text']);
    $search = array("
        $replace = array('
            $post = str_replace($search,$replace,$post);
            $post = preg_replace_callback('/(\[code:1:[0-9a-fA-F]{10}\])(.+)(\[\/code:1:[0-9a-fA-F]{10}\])/s',code_callback,$post);
            $post = str_replace("\r\n","
            $post = str_replace('specialtag_newlines_lol',"\n",$post);

First, I replace all the common tags, then I strip newlines from lists. Without that, the page doesn't validate because you end up with

    , and you haven't have
    tags in a list.
    Once that's done, I use a callack to parse tags. They need special handling because I use geshi to parse the code inside them into nicely colured text, much like the source tags here on GDNet.
    Inside the code callback function, I convert special characters back to their normal equivalents (( becomes ( and so on), since phpbb converts those, and geshi will convert them back if it needs. Then whitespace is trimmed, and the code is parsed with geshi. Finally, newlines get converted into a tag, so when I come to convert newlines to br's, I don't end up with
    all over my code.
    Back out of the callback, I convert newlines to
    tags, and then put the newlines back into the code blocks.

    I spent most of yesterday watching Lost, season 1. I started watching it when it was on TV here, but I only saw the first 4 or 5 episodes, then missed about 5 of them and decided it was pointless trying to get back into it, and I'll just get the DVD when it comes out.
    I've still got the second half of the season to watch tonight (Another 9 hours in total). Why is it that when my MSN name is set to "Steve - Watching Lost (Away)", everyone tries to sodding talk to me? I had 5 people leaving messages, including one who kept saying "Pssssst!" "timmy!" and sending repeated nudges. However, my MSN doesn't bleep or anything when people send me messages/nudges when media player is running fullscreen...
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!