只是无法摆脱` `来自html字符串的字符

时间:2012-08-28 13:47:53

标签: php string

这是我想要清理的字符串。

 '&#13;        &#13;    <span>CR - CROPLAND</span>&#13;'

这是我的呼吁声明:

 trim(strip_tags(clean_string($leftTd->innerhtml())))

这是我试图用它来清理它的功能,但它不起作用。

 function clean_string($string){
   for($control = 0; $control < 32; $control++) {
      $string = str_replace(chr($control), "", $string) ;
   }
   return $string ;
}

我也尝试过:

 // $string = ereg_replace("[^A-Za-z0-9\-\./,']", " ",$string) ;

,但它不起作用。

帮助! 具体来说,我试图摆脱&#13;。究竟是什么呢。谷歌搜索没有帮助\

由于

3 个答案:

答案 0 :(得分:2)

在运行替换之前,请使用HTML entities解码html_entity_decode()

function clean_string($string){
   $string = html_entity_decode($string);
   //replace here
   return $string ;
}

答案 1 :(得分:0)

您必须搜索字符串“&#13;”,因为字面打印就像那样。它尚未被翻译成它所代表的特殊性格。

str_replace("&#13;", "", $string);

或更有用:

function clean_string($string){
   for($control = 0; $control < 32; $control++) {
      $string = str_replace("&#$control;", "", $string) ;
   }
   return $string ;
}

注意:角色13显然是“垂直标签”......有趣。 http://www.robelle.com/smugbook/ascii.html

答案 2 :(得分:0)

只需使用html_entity_decode();

$output = html_entity_decode($input);
相关问题