I have a string like “You can win tonight $200,000. Sign up now!”
Where the prize is changing from string to string, so I have to do it somehow using php regex or somthing like that.
How to get just this value from this string using php?
Is there a simple regex function?
Thanks in advance.
You’re looking for
preg_match, I think:Breaking it down:
The regular expression look for a dollar sign (which has special meaning in regular expressions, so we escape it with backslash, so it’s taken as literal dollar sign), followed by 1 or more digits (0-9) and commas.
Note that if
preg_matchitself returns false, it’s because the string didn’t match the regexp, and in that case, there will be no$match[0]to read