You are right, I copied and pasted the code before I finalized it. the correct version is :
For whatever reason, I have version 5.2.12 and when I use $basename['filename'] it strips the extension off, the only way for me to get it to wrok correctly was to use $basename['basename']. Maybe the is an undocumented feature...LOL
$in = fopen('input.txt', 'r');
$out = fopen('output.txt', 'w');
// Check used later...
$pre520 = version_compare(phpversion(), '5.2.0', '<');
while(($line = fgetcsv($in, 0, ',')) !== false)
{
$search = $line[9];
$basename = pathinfo($search);
// Previous to 5.2, pathinfo() doesn't give the value of "filename", so we'll get it
if($pre520)
{
$basename['filename'] = substr($basename['basename'], 0, strlen($basename['extension'])+1);
}
$i = strlen($basename['basename']);
$a = '0';
while($i > $a)
{
$filename = substr($basename['filename'].'.'.$basename['extension'], $a, $i);
if(file_exists($filename))
{
$f = array($filename);
fputcsv($out, $f, ',');
break; // Break out of this while
}
++$a;
}
}