Writing a function to parse BB Code and RSS Feeds each time you need them is a pain. Here’s a use function to throw into an include or just have on hand for later.

A little while ago I was stuck reading forum content outside of the forums. Pulling anything from the database is easy but without a nice set of functions to handle the odd strings that can somehow come out, it can be a little difficult. This function here made everything a lot better. Unless your forums look like this:

forums


This string handling function will do most of work for you once you set the tags. To improve on the function, just make parsed tags dynamic and pass them into the function when calling it.

 PHP |  copy code |? 
01
02
// Setup functions
03
function get_string_between($string, $start, $end){
04
        $string = " ".$string;
05
        $ini = strpos($string,$start);
06
        if ($ini == 0) return "";
07
        $ini += strlen($start);   
08
        $len = strpos($string,$end,$ini) - $ini;
09
        return substr($string,$ini,$len);
10
}
11
 
12
$fullstring = "this is my [tag]app[/tag]";
13
$parsed = get_string_between($fullstring, "[tag]", "[/tag]");
14
 
15
echo $parsed; // (result = app) 
16
Was this useful? Help share it:
  • Print this article!
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Mixx
  • Fark
  • MySpace
  • Technorati
  • Reddit