所以,我試過使用trim和str_replace,而我只是無法弄清楚。我GOOGLE了它,似乎沒有任何工作。如何擺脫字符串中的空白,php
這裏是我的代碼:
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);
?>
謝謝!
編輯:
我道歉,我應該已經張貼了我的輸出和預期輸出。
輸出:123123歐元等於162 362.3美元 預期輸出:123123歐元等於162362.3美元
一旦我擺脫了空白的,我可以用money_format功能才能正常顯示。
你在哪裏觀察這個空白?在最終的HTML頁面中? – 2012-01-31 07:49:42
你能發表當前的產出和預期的產出嗎? 「似乎沒有任何工作」並不是真正的具體問題清單:)。你想要什麼,最好是爲什麼你想要它?現在會發生什麼?等等。 – Nanne 2012-01-31 07:51:44
對不起,我已經添加了輸出和預期的輸出,謝謝指出! – stytown 2012-01-31 08:16:48