2011-03-25 109 views
3

我有一个字符串(使用卷曲其他网站获取的。随着我试图替换某个字符什么也没有,没有空间的字符串,刚刚摆脱它。无法从字符串中删除某些字符。 PHP

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 Code: '&#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"> 

回答

6

好吧,我花了些时间,看着它,我认为这应该工作更好一点:

$char = utf8_decode('this is a string with char in it  couple of times'); 
$r = utf8_decode('Â'); 
$upd = str_replace($r, '', $char); 
对我而言,这产生于:

老答案删除...

+0

我甚至不知道我在正确使用的htmlspecialchars功能。我已经将空间改为''了。但我想摆脱所有在一起的字符。我也试过了,只是char str_replace('','',$ sting) – goingsideways 2011-03-25 01:09:46

+0

如果这样做不起作用,那么它不能正确识别它看起来的字符。你碰巧有一个样本输入字符串? – whoughton 2011-03-25 01:12:15

+0

@whoughton - 检查编辑。我给你举了一个例子 – goingsideways 2011-03-25 01:15:51