php - get number from file with regexp? -
i've got files named
1234_crob.jpg 1234.jpg 2323_örja.bmp 2323.bmp etc.
how can retrieve numbers e.g. 1234 , 2323?
if file names start numbers there no need use regular expressions, try instead:
foreach (glob('/path/to/dir/{0,1,2,3,4,5,6,7,8,9}*', glob_brace) $file) { echo $file . ' = ' . intval(basename($file)) . "<br />\n"; }
this updated glob pattern match filenames start digit, requested.
@ghostdog74: you're right.
foreach (glob('/path/to/dir/{0,1,2,3,4,5,6,7,8,9}*', glob_brace) $file) { echo $file . ' = ' . filter_var(basename($file), filter_sanitize_number_int) . "<br />\n"; }
Comments
Post a Comment