I'm trying to get information from filenames.
It loops through everything in the directory, now I just need it to chop them up.
The format:
number-name.ext
I need $number to equal everything before the first dash, and $name to equal everything after the dash until the last period.
I've been trying a bunch of functions, but I can't get it quite right.
current code:
PHP Code:
$handle = opendir('scans/3/'); while (false !== ($file = readdir($handle))){ $extplace = strchr($file, "."); $number = substr($file,0,strpos($file, "-")); $name = strchr($file, "-"); echo $number.'/'.$name.'<br />'; }
Currently it get's the number correctly, I just don't know how to do the name.
echo will be something like
10/-name.jpg
EDIT:
nvm, I'm pretty sure this worked
PHP Code:
$name = strchr($file, "-"); $name = substr($name, 1, strlen($name)-5);
Last edited by Skeddles; 11-15-2009 at 04:44 PM..
|