Home  >  Article  >  Backend Development  >  php 解析dom后 汉字都编程相仿ascii的东西了

php 解析dom后 汉字都编程相仿ascii的东西了

WBOY
WBOYOriginal
2016-06-13 12:56:02819browse

php 解析dom后 汉字都编程类似ascii的东西了
php 解析dom后 汉字都编程类似ascii的东西了,但是网页正常显示汉字,查看源代码后成ascii的东西了
查看源代码的效果

<div class="content" contentScore="8405"><br />
            	<p><br />
	&#12288;&#12288;&#36825;&#20004;&#20010;&#26376;&#65292;&#24494;&#20449;&#33829;&#38144;&#20687;&#30127;&#20102;&#19968;&#26679;&#22312;&#34067;&#24310;&#12290;&#25105;&#20063;&#19968;&#30452;&#22312;&#20851;&#27880;&#36825;&#20010;&#26032;&#29609;&#24847;&#65292;&#28176;&#28176;&#30340;&#65292;&#26377;&#20102;&#19968;&#20123;&#30475;&#27861;&#65292;&#20170;&#22825;&#19981;&#22952;&#20998;&#20139;&#19968;&#19979;&#12290;</p><br />
<p><br />
	&#12288;&#12288;&#25105;&#20808;&#26159;&#20851;&#27880;&#20102;&ldquo;&#29579;&#21147;&#23439;&rdquo;&#65292;&#25105;&#36319;&#20182;&#35828;&#19968;&#21477;&#35805;&#65292;&#20182;&#24456;&#24555;&#22238;&#36807;&#26469;&#19968;&#38271;&#27573;&#35821;&#38899;&#65292;&#28982;&#21518;&#20877;&#35828;&#65292;&#23601;&#19981;&#25645;&#29702;&#25105;&#20102;&#12290;&#20174;&#19968;&#24320;&#22987;&#25105;&#23601;&#30693;&#36947;&#65292;&#36825;&#19968;&#23450;&#26159;&#26426;&#22120;&#20570;&#30340;&#65292;&#20986;&#20110;&#22909;&#22855;&#65292;&#25105;&#26102;&#19981;&#26102;&#36319;&#20182;&#35828;&#35828;&#35805;&#65292;&#19981;&#22823;&#26377;&#22238;&#22797;&#65292;&#26377;&#22238;&#22797;&#20063;&#26159;&#37027;&#31181;&#36319;&#35841;&#35828;&#37117;&#21487;&#20197;&#30340;&#25171;&#21704;&#21704;&#30340;&#35805;&#12290;&#26377;&#19968;&#22825;&#31361;&#28982;&#25509;&#21463;&#21040;&#29579;&#21147;&#23439;&#21457;&#26469;&#30340;&#24494;&#20449;&#65292;&#37324;&#38754;&#35828;&#20102;&#20182;&#22312;&#22025;&#20852;&#28436;&#21809;&#20250;&#30340;&#24773;&#20917;&#65292;&#25105;&#24819;&#36825;&#20063;&#26159;&#24405;&#22909;&#36890;&#36807;&#24494;&#20449;&#24179;&#21488;&#32479;&#19968;&#21457;&#36865;&#30340;&#21543;&#12290;</p>


思路:把数据处理后,放到$ContentBox变量中,如果直接输出$ContentBox->nodeValue,则正常看到网页和查看源代码都正常显示,但是html标签(如div src)和图片都没了,如果将$ContentBox 复制到另一个dom里,正常查看网页也正常显示,但是查看源代码文字就成类似ascii的东西(标签和图片都没丢),复制代码如下,
$Target = new DOMDocument;<br />
        $Target->appendChild($Target->importNode($ContentBox, true));<br />
<br />
		echo $Target->saveHTML();


这是什么原因呢,如何解决


------解决方案--------------------
$Target  = new DOMDocument('1.0', 'utf-8'); $ContentBox = $Target->importNode($ContentBox, true);   echo $Target->saveXML($ContentBox);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn