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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -