简体   繁体   中英

Cannot remove certain character from a string. PHP

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: '&#194';
  • 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">

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM