1.) [man]substr[/man]($string, 0, strrpos($string, '.'));
2.) Easy, in the loop, compare the file-name with the current language 😉
function getLanguages() {
global $sitepath, $language; // Include sitepath and current language
$dir = $sitepath.'/includes/languages';
$dh = dir($dir);
if(!$dh) return 'Unable to open directory: '.$dir;
while(false !== ($item = $dh->read())) {
if($item != '.' && $item != '..')
$files[] = $item;
}
$dh->close();
if(empty($files) || !isset($files)) return 'No languages to select from.';
$output = '<select name="language">';
foreach($files AS $lang) {
$display = substr($lang, 0, strrpos($lang, '.'));
$selected = ($language == $lang) ? ' selected="selected"' : '';
$output .= '
<option value="'.$dir.'/'.$lang.'"'.$selected.'>'.$display.'</option>';
}
$output .= '</select>';
return $output;
}
That should incorporate all your modifications. Now, if $language isn't set elsewhere or is a global (like held within $_SESSION) then you need to modify the above code just slightly.