tag array sanitizing

$tagList = “tag1, , tag2, tag4 , , , , “;

function sanitizeTagList($tagList){
$rs = preg_replace(“/\s+/”,””,$tagList); // remove blank
$rs = explode(‘,’,$rs); // make string as array
$rs = array_unique($rs); // remove repeated tag
$rs = array_diff($rs,array(“”)); // remove “” element
return $rs;
}
$rs = sanitizeTagList($tagList);
// array(3) => {
[0] => “tag1”,
[1] => “tag2”,
[2] => “tag4”,
}

Advertisements