2011-11-24 43 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);