Filenames with single-quotes
Posted: Fri Nov 05, 2010 4:05 pm
I have the below code that lists all file names in a directory, sorted in alphabetical order. It works great, until a filename has an apostrophy in it, then it breaks. I tried urlencoding the filenames, but then the href can't fine that filename when I click on it.
HELP!! and thank you
HELP!! and thank you
Code: Select all
<?php
function alpharead3($dir){
if(!$dir){$dir = '.';}
foreach (glob("$dir/*") as $item){$sort[]= end(explode('/',$item));}
$killit = array('index.html', 'index.php', 'thumbs.db', 'styles.css');
$killcounter = 0;
foreach($sort as $sorteditem){
foreach($killit as $killcheck){
if(strtolower($sorteditem) == strtolower($killcheck))
{unset($sort[$killcounter]);}
}$killcounter++;}
if($sort){natsort($sort);}
foreach($sort as $item){$return[]= $item;}
if(!$return){return array();}
return $return;
}
//some basic usage
$folder = 'some_directory';
foreach(alpharead3($folder) as $item)
{
echo "<li><a href='" . $folder . "/" . $item . "'>" . $item . "</a></li>";
}
?>