从php中删除奇怪的字符

时间:2013-10-29 14:47:03

标签: php special-characters

我试图从PHP数组中删除一些特殊/奇怪的字符 数据以JSON html形式出现,如下所示:

<table class=\"MsoNormalTable\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"728\" style=\"width:545.75pt; margin-left:-1.7pt; border-collapse:collapse\">\r\n<tbody>\r\n<tr style=\"height:15.0pt\">\r\n<td width=\"303\" valign=\"top\" style=\"width:227.0pt; border:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt\">\r\n<p class=\"MsoNormal\" style=\"line-height:115%\"><span style=\"font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:black\">Policy number:<\/span><\/p>\r\n<\/td>\r\n<td width=\"425\" nowrap=\"\" valign=\"bottom\" style=\"width:318.75pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt\">\r\n<p class=\"MsoNormal\" style=\"line-height:115%\"><span style=\"font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:black\">&nbsp;LAP3_MC_2011030004&nbsp;\r\n<\/span><\/p>\r\n<\/td>\r\n<\/tr>\r\n<tr style=\"height:15.0pt\">\r\n<td width=\"303\" nowrap=\"\" valign=\"bottom\" style=\"width:227.0pt; border:solid windowtext 1.0pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt\">

我正在阅读数据并使用DomCrawler过滤掉我需要的文件,输出是:

string(4) "�Mr�"

尝试过:

iconv("UTF-8", "ISO-8859-1//TRANSLIT", $l->nodeValue);

不会删除奇怪的钻石字符

知道怎么解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

尝试

 iconv("UTF-8", "ISO-8859-1//IGNORE", $l->nodeValue);

OR

 mb_convert_encoding ( $l->nodeValue, "ISO-8859-1", "UTF-8" )