2011-11-24 38 views
2

我通過CURL從網站獲取文本,但在原始網站上有 ,但是當我將它返回給我的時候,這只是一個空間然而,即使對於str_replace,(string),strval()等,也沒有任何幫助。在CURL請求後使用PHP刪除 

任何人都可以幫忙嗎?

當前代碼

$country = $s->fetchBetween('<dt>Country:</dt><dd>','</dd>', $result); 
    $country = strval($country); 
    $country = str_replace("&nbsp;", "", strval($country)); 
    echo "start-{$country}-end"; 
    exit; 

的網站,我就值 「冰壺」 顯示爲

India&nbsp; 
+0

只是出於好奇,你試過'trim()'? – hafichuk

回答

2

嘗試,而不是下面。

$country = str_replace("&amp;nbsp;", "", strval($country)); 
+0

仍然完全相同 –

+0

最後使用$ country = substr($ country,0,-1);然而,仍然很想知道這裏究竟發生了什麼 –

0

試試看。

$string = 'x&nbsp;&nbsp;&nbsp;&nbsp;x '; 
$pattern = '/&nbsp;/'; 
echo preg_replace($pattern, '', $string);