Page 1 of 1

str_replace not replacing....

Posted: Fri Oct 16, 2009 5:11 pm
by petroz
Hi Guys,

I am trying to remove a whitespace(At least I think it is a space) character from a string.

http://www.google.com/ig/calculator?=hl=en&q=1USD=?IDR
is the url where I am getting the string.

{lhs: "1 U.S. dollar",rhs: "9 433.96226 Indonesian rupiahs",error: "",icc: true}
is the results I am parsing.

9 433.96226
the space between the 9 and 4 is what I am trying to remove...

I cant seem to get regex or str_replace to remove this.

Any help would be greatly appreciated...

Code: Select all

<?
 
include 'db.php';
 
//IDR UPDATE
$urlIDR = "http://www.google.com/ig/calculator?=hl=en&q=1USD=?IDR";
//Set up a CURL request, telling it not to spit back headers, IDR to throw out a user agent.
$chIDR = curl_init();
  
curl_setopt($chIDR, CURLOPT_URL, $urlIDR);
curl_setopt($chIDR, CURLOPT_HEADER,0); //chIDRIDRe this to a 1 to return headers
curl_setopt($chIDR, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($chIDR, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chIDR, CURLOPT_RETURNTRANSFER, 1);
 
$dataIDR = curl_exec($chIDR);
curl_close($chIDR);
 
// return url = {lhs: "2.5 Australian dollIDR",rhs: "1.42254939 British pounds",error: "",icc: true}
 
$topIDR = str_replace('{lhs: "1 U.S. dollar",rhs: "', '', $dataIDR);
$botIDR = str_replace('",error: "",icc: true}', '',$topIDR);
$nospaceIDR = str_replace(' ','', $botIDR);
//preg_match([0-9\.\-], $botIDR, $nospaceIDR);
$IDR = str_replace('Indonesianrupiahs', '', $nospaceIDR);
 
 
$updateIDR = "UPDATE rates SET rate = '$IDR', time = '$time' WHERE code = 'IDR'";
 
$updateIDRresult = mysql_query($updateIDR)
    or die (mysql_error());     
    
echo $IDR; 
echo '<br/>';
 
?>