I am working with a string like:
$string = "2017 MODEL YEAR 6.7L POWER STROKE V8 DIESEL 6-SPEED AUTO TRANS 3.55 ELECTRONIC LOCKING AXLE FX4 OFF-ROAD PACKAGE .SKID PLATES 10000-lb. GVWR PACKAGE";
Within the string is the string 10000-lb. GVWR PACKAGE. My goal is to apply number_format to 10000 so that the string reads 10,000-lb. GVWR PACKAGE.
I have been testing with preg_replace and can get to the number using:
preg_replace('!\d+-lb\.!', '\0', $string);
I attempt to apply number_format like:
preg_replace('!\d+-lb\.!', number_format('\0'), $string);
but receive the following error:
number_format() expects parameter 1 to be float, string given
Applying intval() to the match returns a 0 and not the expected 10,000.
I am not sure how to proceed. The catch I have also identified is that I do not want number formatting applied to the first 2017. Do I need to adjust the preg_match to not be as specific or perhaps apply a preg_match to the match within the first preg_match to get the number only?