Fork me on GitHub

article

Even more progress

October 24, 2004 | Web Design & Development

I finally figured out how to get lists into and out of the db without using html in the db.

WooHoo!

// find all lists in the text
preg_match_all("|(\[list\])(.*?)(\[/list\])|s",$text, $matches);
$i = "0";
// run each list
foreach($matches[2] as $lis) {
    // break out each list element
    $eachli = explode("[*]", $lis);
            // start list string
            $listring = "<ul>\n";
    foreach($eachli as $key => $li) {
        // first array element is always
        // empty and we don't need it
        if($key > 0) {
            // build list elements
            $listring .= "<li>".$li."</li>\n";
        }
    }
    // close list
    $listring .= "</ul>\n\n";
    // insert new list text into original text
    $text = str_replace($matches[0][$i], $listring, $text);
    $i++;
}

Ha! I write this like someone’s actually gonna read it!