Let’s say in PHP I have a string-variable : "This takes between 5 and 7 days"
I need to store some sensible information about the time it takes in an integer.
I’m satisfied if the result would be 5.
I tried stripping non-numeric characters, but end up with 57 then.
How can this be done in a better way?
Use
preg_matchto match the first digit group using a regex:Using
preg_match_allyou could match all digit groups (5and7in this example):