{"id":364,"date":"2019-04-06T23:10:07","date_gmt":"2019-04-07T04:10:07","guid":{"rendered":"https:\/\/greg-kennedy.com\/wordpress\/?p=364"},"modified":"2019-04-06T23:11:23","modified_gmt":"2019-04-07T04:11:23","slug":"bbcode-parser-in-php","status":"publish","type":"post","link":"https:\/\/greg-kennedy.com\/wordpress\/2019\/04\/06\/bbcode-parser-in-php\/","title":{"rendered":"BBCode Parser (in PHP)"},"content":{"rendered":"\n<p>For a while now I&#8217;ve been working on a little blog engine in PHP.  As part of the post rendering, I&#8217;ve settled on BBCode to do all markup and layout.<\/p>\n\n\n\n<p>This meant I would need a BBCode parser.  So, I started writing one.  And because my projects always go this way, I ended up sinking more time into the BBCode parser than the blog engine itself &#8211; trying to get every weird corner case and not produce malformed HTML on output.  The primary goals were:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Easy to use (one file with one function)<\/li><li>Correct (Unicode safe, always-valid HTML, reasonable fallbacks)<\/li><li>Easy to understand (avoid massive regexes)<\/li><\/ul>\n\n\n\n<p>Eventually, I ended up just splitting this piece off into its own project, since it may be useful beyond just my tiny blog.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/greg-kennedy\/php-bbcode\"><strong>https:\/\/github.com\/greg-kennedy\/php-bbcode<\/strong><\/a><\/h2>\n\n\n\n<p>I know there are a million BBCode parsers out there (and even a PHP extension to do it), some extensible and so on.  This one is mine.  Would love pull requests.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For a while now I&#8217;ve been working on a little blog engine in PHP. As part of the post rendering, I&#8217;ve settled on BBCode to do all markup and layout. This meant I would need a BBCode parser. So, I started writing one. And because my projects always go this way, I ended up sinking [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-364","post","type-post","status-publish","format-standard","hentry","category-software"],"_links":{"self":[{"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/posts\/364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/comments?post=364"}],"version-history":[{"count":2,"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/posts\/364\/revisions"}],"predecessor-version":[{"id":366,"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/posts\/364\/revisions\/366"}],"wp:attachment":[{"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/media?parent=364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/categories?post=364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/tags?post=364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}