note 49952 deleted from function.substr by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Nov 2008 20:25:18 +0000 |
| Subject: | note 49952 deleted from function.substr by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147211@lists.php.net to get a copy of this message | ||
Note Submitter: Robert
----
It is also good to use substr() to get a file extension when manipulating with files. For example:
<?php
$dir = "/full/path/to/folder";
if(is_dir($dir))
{
if($dh = opendir($dir))
{
while(($file = readdir($dh)) !== false)
{
if(substr($file,strlen($file)-4,4) == ".txt")
{
echo "Filename: $file<br/>\n";
}
}
closedir($dh);
}
else
{
echo "Cannot open directory";
}
}
else
{
echo "Cannot open directory";
}
?>
Hopefully this helps