Jump to content

preg_match Error


CaptainC

Recommended Posts

I have an error with this statement:

[code]preg_match("[0-9]+\.?[0-9]*", $text_string, $match_array);[/code]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: preg_match(): Unknown modifier '+' in ...[/quote]
I thought it had something to do with the slashed in php strings, but I have not been able to get it right.

Any thoughts?
Link to comment
https://forums.phpfreaks.com/topic/6013-preg_match-error/
Share on other sites

[quote]
Would this regex be the way to go if I wanted to pull out the number value from this example?:

<b><i>$456.50</i></b>

And have preg_match pull out "456.50" ?
[/quote]
If the string will only contain one number then it should be fine. The regex will match a number that ends with a "." however, which may not be what you want. You could change it to the following to avoid that.
[code]
/[0-9]+(.[0-9]+)?/
[/code]
Link to comment
https://forums.phpfreaks.com/topic/6013-preg_match-error/#findComment-21650
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.