fork download
  1. <?php
  2.  
  3. $pattern = '/^([A-Za-z0-9-]+)_(\d+_?\d+?)_(\d+)\.(jpe?g|webp)$/ui';
  4. $file = '552-1209-0019_5646_1.jpg';
  5.  
  6. if (preg_match($pattern, $file, $matches)) {
  7. $sku = $matches[1];
  8. $colorId = $matches[2];
  9. $position = $matches[3];
  10. $ext = strtolower($matches[4]);
  11. var_dump($sku, $colorId, $position, $ext);
  12. } else {
  13. echo "Некоректне ім'я файла";
  14. }
Success #stdin #stdout 0.03s 25876KB
stdin
Standard input is empty
stdout
string(13) "552-1209-0019"
string(4) "5646"
string(1) "1"
string(3) "jpg"