If you can use str_replace() instead of ereg*_replace(), use it !
Don't use eregi_relace(".txt", "", $string) but str_replace(".txt", "", $string).
But if you want to remove any extension, use the following :
<?
$fch = "photo of java.lang error"; // the filename
$lim = 5; // the maximum length of extension
$pnt = strrpos($fch, "."); // finds the last point
if((strlen($fch) - $pnt - 1) <= $lim) { // checks if the extension is lower or egual to the limit
$fch = substr($fch, 0, $lim); // if true, removes the extension
}
echo $fch; // echoes the filename
?>