function smile($text, $reverse = 0) { $code = array(); $images = array(); for ($i = 1; $i <= 22; $i++) { $code[] .= ":$i:"; } for ($i = 1; $i <= 22; $i++) { $images[] .= "<img src="/images/smiles/$i.gif" alt="" />"; } $count = 3; if ($reverse) { $text = str_replace($images, $code, $text, $count); } else { $text = str_replace($code, $images, $text, $count); } return $text; }