The preg_replace function has always baffled me for some reason.
I'm using an API where a $score variable returns something like this:
proxyScore=1.80
What's the proper preg_replace statement to get rid of everything but the numerical content, including the decimal point? The text 'proxyScore=' will always be the same. My opinions expressed on this site, in no way represent those of Boonex or Boonex employees. |
I'm not really good with regular expressions so i'll suggest two alternative ways: 1. $numerical_val = str_replace('proxyScore=','',$string); (as you said 'proxyScore=' is always a part of the string) 2. $ar = explode('=',$string); 1st option i think is the best for your case, and i believe there's no need to use regex at all... |
You're right.... don't know what I was thinking. Since the $score variable always returns the exact same text, followed by the numeric score, such as 'proxyScore=1.80', I just used str_replace like this:
$score = file_get_contents($query);
if ($numericScore > .5) {
It works fine. My opinions expressed on this site, in no way represent those of Boonex or Boonex employees. |