while (preg_match_all('`[('.$tags.')=?(.*?)](.+?)[/1]`',$string,$matches)) foreach ($matches[0] as$key=>$match) {
list($tag,$param,$innertext) = array($matches[1][$key],$matches[2][$key],$matches[3][$key]);
switch ($tag) {
case'b':$replacement="$innertext"; break;
case'i':$replacement="$innertext"; break;
case'size':$replacement="$innertext"; break;
case'color':$replacement="$innertext"; break;
case'center':$replacement="
case'quote':$replacement="
$innertext".$param?" $param":''; break;
case'url':$replacement='$innertext"; break;
case'img':
list($width,$height) =preg_split('`[Xx]`',$param);$replacement="';
break;
case'video':$videourl=parse_url($innertext);parse_str($videourl['query'],$videoquery);
if (strpos($videourl['host'],'youtube.com') !==FALSE)$replacement=.$videoquery['v'] .'" type="application/x-shockwave-flash" width="425" height="344">';
if (strpos($videourl['host'],'google.com') !==FALSE)$replacement=.$videoquery['docid'] .'" width="400" height="326" type="application/x-shockwave-flash">';
break;
}$string=str_replace($match,$replacement,$string);
}
return$string;
}?>
[EDIT BY danbrown AT php DOT net: Contains a bugfix provided by (ramonvandam AT gmail DOT com) on 04-SEP-09 to address an improperly-defined parameter. Also contains a bugfix provided by (pompei2 AT gmail DOT com) on 15-FEB-10 to address improperly-closed tags. Plus, contains another bugfix provided by (angad AT wootify DOT com) on 18-JUL-2011 to fix an issue where unsupported tags provided to the function could cause the script to time out.]