Mostrar ñ y tildes en php


24 de Noviembre del 2020

Buen dia... tengo una funcion que lista directorios en un tree view. Tengo una funcion para subir archivos a esos directorios que estan en un servidor. Al subir un archivo con ñ por ejemplo: Albañil lo sube bien al servidor sin problemas pero no se me ve en mi sistema web a la hora de cargarlo en el tree view, aca les dejo la funcion..si me pudieran ayudar gracias de antemano.

Utilizo una expresion regular la cual creo esta correcta.

protected function path($id) {
$id = str_replace('/', DIRECTORY_SEPARATOR, $id);
$id = trim($id, DIRECTORY_SEPARATOR);
$id = $this->real($this->base . DIRECTORY_SEPARATOR . $id);
return $id;
}

public function lst($id, $with_root = false) {
$dir = $this->path($id);
$lst = @scandir($dir);

if(!$lst) { throw new Exception('Could not list path: ' . $dir); }
$res = array();
foreach($lst as $item) {

if($item == '.' || $item == '..' || $item === null) { continue; }
$tmp = preg_match('([^ a-z -я-_0-9.]+)ui', $item);


if($tmp === false || $tmp === 1) { continue; }
if(is_dir($dir . DIRECTORY_SEPARATOR . $item)) {

$res[] =array('text' => $item, 'children' => true, 'id' => $this->id($dir . DIRECTORY_SEPARATOR . $item), 'icon' => 'folder') ;

}
else {
$res[] = array('text' => $item, 'children' => false, 'id' => $this->id($dir . DIRECTORY_SEPARATOR . $item), 'type' => 'file', 'icon' => 'file file-'.substr($item, strrpos($item,'.') + 1));

}
}
if($with_root && $this->id($dir) === '/') {

$res = array(array('text' => basename($this->base), 'children' => $res, 'id' => '/', 'icon'=>'folder', 'state' => array('opened' => true, 'disabled' => true)));
}
return $res;
}