【问题标题】:Removing   with PHP after CURL request在 CURL 请求后使用 PHP 删除
【发布时间】:2023-04-07 16:43:01
【问题描述】:

我通过 CURL 从网站获取文本,但它在原始网站的末尾有即使使用 str_replace、(string)、strval() 等也有帮助。

有人可以帮忙吗?

当前代码

    $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;

【问题讨论】:

  • 只是出于好奇,你试过trim()吗?

标签: php html curl


【解决方案1】:

请尝试以下方法。

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

【讨论】:

  • 最终使用了 $country = substr($country, 0, -1);但是仍然很想知道这里到底发生了什么
【解决方案2】:

试试这个。

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

【讨论】:

    猜你喜欢
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    • 2014-11-16
    • 1970-01-01
    • 2014-03-03
    相关资源
    最近更新 更多