I actually gave you the answer 🙂
$smileys = array();
while (list ($key, $val) = each ($filelist)) {
$oldval = $val;
$val = basename($val, ".gif") ;
$val = basename($val, ".png") ;
$val = basename($val, ".jpg") ;
$smileys[":".$val.":"] = $oldval;
}
On the programming practices side (as you say you're new to PHP), using foreach() instead of while() makes for slightly cleaner code - especially since you don't need $key.
Also, you don't need to sort $filelist (the same replacements will be made no matter what order they appear in the list in).
Instead of using basename() (since you don't have any path information to strip), just lop off everything after the last '.' inclusive $val = substr($val, 0, strrpos($val,'.'));. This assumes that you know everything in that directory is going to be the right sort of thing - but you're assuming that already.
Since you don't need to sort the file list, you can combine the two loops and discard the $filelist array completely. Get a file name from the directory handle, put an entry in the $smileys array, get another name, ....