So, I’ve tried using trim and str_replace, and I just can’t figure it out. I’ve googled it, and nothing seems to be working.
here is my code:
function convertcurrency($euro){
if (is_numeric($euro)) {
$currency = file_get_contents("http://www.google.com/ig/calculator?hl=en&q=".$euro."EUR%3D%3FUSD");
$contents = array_map('trim', explode(" ", $currency));
$getint = array_map('trim', explode("\"", $contents[3]));
unset($getint[0]);
$usdollar = implode(" ", $getint);
echo "$euro Euro's is equal to $usdollar U.S. Dollars";
}
else{
echo "$euro is not a number, please enter a number.";
}
}
convertcurrency(123123);
?>
Thanks!
Edit:
I apologize, I should have posted my output, and expected output.
Output: 123123 Euro’s is equal to 162 362.3 U.S. Dollars
Expected output: 123123 Euro’s is equal to 162362.3 U.S. Dollars
Once I get rid of the whitespace, I can use the money_format function to display it properly.
You will need to use a regular expression to replace all text.
That should work for you.