无法从字符串中删除某些字符。 PHP

发布于 2024-10-26 14:26:41 字数 771 浏览 0 评论 0原文

我有一个字符串(使用 cURL 从另一个网站检索)。使用该字符串,我尝试将某个字符替换为空,没有空格,只需删除它。

foreach($propinfo_desc_div as $child)
{
    // ONLY SHOW STRINGS LONGER THAN 10 CHARS
    $strlen = strlen($child->nodeValue);
    if($strlen > 10)
    {
        $description = str_replace(htmlspecialchars('Â'),'', $child->nodeValue);
        echo $description;
        echo "<br />";
    }
}

有关该字符的一些信息:

  • ASCII 字符:
  • ASCII 代码: '&#194';
  • ASCII 描述:拉丁大写字母 A 抑扬符

字符串示例:

 fully serviced daily. Â Â Spend the evenings relaxing in the frie

@Whoughton 的解决方案

<meta http-equiv="content-type" content="text/html; charset=utf-8">

I have a string(retrieved from another website using cURL. With the string I am trying to replace a certain character with nothing, no space, just get rid of it.

foreach($propinfo_desc_div as $child)
{
    // ONLY SHOW STRINGS LONGER THAN 10 CHARS
    $strlen = strlen($child->nodeValue);
    if($strlen > 10)
    {
        $description = str_replace(htmlspecialchars('Â'),'', $child->nodeValue);
        echo $description;
        echo "<br />";
    }
}

Some info on the character:

  • ASCII Char: Â
  • ASCII Code: 'Â';
  • ASCII Description: Latin Capital Letter A Circumflex

string example:

 fully serviced daily. Â Â Spend the evenings relaxing in the frie

Solution by @Whoughton

<meta http-equiv="content-type" content="text/html; charset=utf-8">

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2024-11-02 14:26:41

好吧,我花了更多的时间看它,我相信这应该会更好一点:

$char = utf8_decode('this is a string with char in it  couple of times');
$r = utf8_decode('Â');
$upd = str_replace($r, '', $char);

这对我来说:

Source: string(51) "this is a string with char in it  couple of times" 
Function: str_replace('Â', '', $char)
Output: string(49) "this is a string with char in it couple of times"

旧答案已删除...

Ok, I spent a little more time looking at it, I believe this should work a little better:

$char = utf8_decode('this is a string with char in it  couple of times');
$r = utf8_decode('Â');
$upd = str_replace($r, '', $char);

This produces, for me:

Source: string(51) "this is a string with char in it  couple of times" 
Function: str_replace('Â', '', $char)
Output: string(49) "this is a string with char in it couple of times"

Old answer removed...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文