Here is some code I used to extract chat transcript from an IRC bot. The basics are there for replacing certain characters with smilies based on the BB smilies.
$filename = "filename";
$filesize = filesize("$filename");
$fp = fopen ( "$filename", "r" ) or die ("couldn't open file"); //opens the numbering database
//$number = fread ( $fp, $filesize );
$array = array();
while ( ! feof ($fp) )
{
$line = fgets ($fp, 1024);
array_push ($array, $line);
}
explode("\n", $array);
$array2 = array();
foreach ($array as $tochop)
{
$rf = ereg_replace (">", ":", $tochop);
$rf2 = ereg_replace ("<", "", $rf);
$a = ereg_replace ("\[", "<br>", $rf2);
$b = ereg_replace ("\]", "", $a);
$c = ereg_replace ("#pacrochat", "", $b);
$d = ereg_replace ("\*\*\*", "", $c);
$d1 = preg_replace('/([^\s\<\>]{15,15})/', '\1 ', $d);
$e = ereg_replace (":)", "<img border=\"0\" src=\"images/smilies/icon_smile.gif\">", $d1);
$f = ereg_replace (";)", "<img border=\"0\" src=\"images/smilies/icon_wink.gif\">", $e);
$g = ereg_replace (":o", "<img border=\"0\" src=\"images/smilies/icon_eek.gif\">", $f);
$h = ereg_replace (":\(", "<img border=\"0\" src=\"images/smilies/icon_frown.gif\">", $g);
$i = ereg_replace (":D", "<img border=\"0\" src=\"images/smilies/icon_biggrin.gif\">", $h);
$j = ereg_replace (":P", "<img border=\"0\" src=\"images/smilies/icon_razz.gif\">", $i);
$k = ereg_replace (" :-? ", "<img border=\"0\" src=\"images/smilies/icon_confused.gif\">", $j);
$l = ereg_replace ("lol", "<img border=\"0\" src=\"images/smilies/icon_lol.gif\">", $k);
$m = ereg_replace (":x", "<img border=\"0\" src=\"images/smilies/icon_mad.gif\">", $l);
$n = ereg_replace (":oops:", "<img border=\"0\" src=\"images/smilies/icon_redface.gif\">", $m);
$o = ereg_replace (":cry:", "<img border=\"0\" src=\"images/smilies/icon_cry.gif\">", $n);
$p = ereg_replace (":roll:", "<img border=\"0\" src=\"images/smilies/icon_rolleyes.gif\">", $o);
$q = ereg_replace (":evil:", "<img border=\"0\" src=\"images/smilies/icon_evil.gif\">", $p);
$r = ereg_replace ("LOL", "<img border=\"0\" src=\"images/smilies/icon_lol.gif\">", $q);
//print "<td width=\"150\"><font size=\"2\">$e</font></td>";
//print $e;
array_push ($array2, $r);
}
$amount = count($array2);
//I did this below manually as I wanted to save on resources. You could have this done by a loop.
print ereg_replace ("<br>", "", $array2[$amount-16]);
print $array2[$amount-15];
print $array2[$amount-14];
print $array2[$amount-13];
print $array2[$amount-12];
print $array2[$amount-11];
print $array2[$amount-10];
print $array2[$amount-9];
print $array2[$amount-8];
print $array2[$amount-7];
print $array2[$amount-6];
print $array2[$amount-5];
print $array2[$amount-4];
print $array2[$amount-3];
print $array2[$amount-2];