hi,
> <?php
> $handle=opendir('/path/to/files');
> while (false !== ($file = readdir($handle))) {
> if (preg_match("/(.*) - (.*).mp3/i", $file, $matches)) {
> $artist = $matches[1];
> $song = $matches[2];
> // insert into db
> }
> }
?>>
I'd suggest to write it like this:
if (preg_match("/([^\-]+) - ([^\-]+)\.mp3/i", $file, $matches)) {
list(, $artist, $song) = $matches;
[..]
}
Match everything that's not a dash [^\-]+ , and escape \. as .
is a regular expression wildcard.
Daniel Lorch
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php