php - 无法从字符串中删除特定字符。 PHP

标签 php special-characters

我有一个字符串(使用 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码:'Â';
  • ASCII 描述:拉丁文大写字母 A Circumflex

字符串示例:

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

@Whoughton 的解决方案

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

最佳答案

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

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

旧答案已删除...

关于php - 无法从字符串中删除特定字符。 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5427447/

相关文章:

php - php 中的数据库查询失败

search - 您如何拼写/发音所有特殊字符和符号

c - 转义字符的行为

mysql - 在 MySQL 查询中使用 ORDER BY 时如何忽略特殊字符

java - Java正则表达式-转义所有特殊的正则表达式字符

php - HTML - 表格内容对齐

PHP 和 mod_fcgid : ap_pass_brigade failed in handle_request_ipc function

php - 我如何 curl www.google.com - 它不断将我重定向到 .co.uk

php - 集成 Paypal 自适应支付 SDK 时未加载类

java - 在 Java 中将 replaceAll 与包含特殊字符的字符串一起使用