function imageize($matches)
{
$from = array('s','c','d','h','[',']');
$to = array('s.gif','c.gif','d.gif','h.gif','','');
return $matches[1] . str_replace($from, $to, strtolower($matches[2])) . $matches[3];
}
$str = preg_replace_callback('#([^\[\]]*?)((?: *\[[akqjtcsdh\d ]+\])+)([^\[\]]*?)#i', 'imageize', $str);
source
share