Preg_replace question

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.
Quote · 30 Dec 2010

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);
$numerical_val = $ar[1];

1st option i think is the best for your case, and i believe there's no need to use regex at all...

Quote · 31 Dec 2010

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);


$numericScore = str_replace("proxyScore=", "", $score);

if ($numericScore > .5) {
header( 'Location: ../404.html' ) ;
}

 

It works fine.

My opinions expressed on this site, in no way represent those of Boonex or Boonex employees.
Quote · 31 Dec 2010
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.