$id = array ();
$code = array(":)", ":(", ";)", ":D", ";;)", ">:D<", ":-/", ":x", ":\">", ":P", ":-*", "=((", ":-O", "X(", ":>", "B-)", ":-S", "#:-S", ">:)", ":((", ":))", ":|", "/:)", "=))", "0:-)", ":-B", "=;", "|-)", "8-|", "L-)", ":-&", ":-$", "[-(", ":o)", "8-}", "<:-P", "(:|", "=P~", ":-?", "#-o", "=D>", ":-SS", "@-)", ":^O", ":-w", ":-<", ">:P", "<):)", ":@)", "3:-o", ":(|)", "~:>", "@};-", "%%-", "**==", "(~~)", "~O)", "*-:)", "8-X", "=:)", ">-)", ":-L", "[-o<", "$-)", ":-\"", "b-(", ":->", "[-X", "\\:D/", ">:/", ";))", "o->", "o=>", "o-+", "(%)", ":-@", "^:)^", ":-j", "(*)", ":)]", ":-c", "~x(", ":-h", ":-t", "8->", ":-??", "%-(");
for ($i = 0; $i < count($code); $i++) {
$id[strtolower($code[$i])] = $i + 1;
}
function toEmoString($str) {
$ret = preg_replace_callback('/(;;\))|(>:D<)|(:-\/)|(:x)|(:">)|(:P)|(:-\*)|(=\(\()|(:-O)|(X\()|(:>)|(B-\))|(#:-S)|(>:\))|(:\(\()|(:\)\))|(:\|)|(\/:\))|(=\)\))|(0:-\))|(:-B)|(=;)|(\|-\))|(8-\|)|(L-\))|(:-&)|(:-\$)|(\[-\()|(:o\))|(8-})|(<:-P)|(\(:\|)|(=P~)|(#-o)|(=D>)|(:-SS)|(:-S)|(@-\))|(:\^O)|(:-w)|(:-<)|(>:P)|(<\):\))|(:@\))|(3:-o)|(:\(\|\))|(~:>)|(@\};-)|(%%-)|(\*\*==)|(\(~~\))|(~O\))|(\*-:\))|(8-X)|(=:\))|(>-\))|(:-L)|(\[-o<)|(\$-\))|(:-")|(b-\()|(:->)|(\[-X)|(\\\:D\/)|(>:\/)|(;\)\))|(o->)|(o=>)|(o-\+)|(\(%\))|(:-@)|(\^:\)\^)|(:-j)|(\(\*\))|(:\)\])|(:-c)|(~x\()|(:-h)|(:-t)|(8->)|(:-\?\?)|(:-\?)|(%-\()|(:\))|(:\()|(;\))|(:D)/i', "setImg", $str);
return $ret;
}
function setImg($m) {
global $id;
$code = strtolower($m[0]);
$i = intval($id["$code"]);
if ($i >= 80) $i += 20;
return "<img src='http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/" . $i . ".gif' title='" . $code . "'>";
}
echo toEmoString("Welcome to Codjng.BlogSpot.Com :D :)) :) :)) :x");
Output:
Welcome to Codjng.BlogSpot.Com