Search code examples
phpregexstring-matching

Split a file name and only take one part for use


I have a $value such as 22214-HAV.jpg or 22214 HAV.jpg (notice no dash)

I want to run a quick function to pull only the number from filename.


Solution

  • A quick solution, which make use of PHPs type juggling

    $number = (int) $filename;