Kez Kez - 4 months ago 36
PHP Question

how to remove file extension for display, but retaining extension for href?

I'm displaying all file from a folder, that part works fine. However, Each link displays the file extension. I have tried removing it, but seems to remove the file name too. I need to display the name of the file without extension, but use a variable with the extension for the

of the link.



$info = pathinfo($filename);
$name = $info['filename'];
$ext = $info['extension'];

$name = pathinfo($filename)['filename'];

$dir = opendir('folder/');
while ($read = readdir($dir))

if ($read!='.' && $read!='..')
echo '<li><a class="" href="folder/'.$read.'">'.$name.'</a></li>';




Any help is much appreciated.


easier way to do this using PHP's ScanDir

$files =  array_diff(scandir('folder/'), array('.', '..'));

foreach($files as $file){

    $name = strstr($file, '.', TRUE);
    echo '<li><a class="" href="folder/'.$file.'">'.$name.'</a></li>';