Home >Backend Development >PHP Tutorial >页面含html文本提交处理,该怎么处理

页面含html文本提交处理,该怎么处理

WBOY
WBOYOriginal
2016-06-13 10:06:43900browse

页面含html文本提交处理

XML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->//xml局部格式如下<aa url="www.xxx.com">    <a href="www.xxx.com?x=s&f=3" target="_blank">常 见 问 答1</a><br><br>       <font size="13"><a href="www.xxx.com?x=s&f=3" target="_blank">常 见 问 答2</a></font><br><br>       <font size="13"><a href="www.xxx.com?x=s&f=3" target="_blank">常 见 问 答3</a></font><br><br>    ]]>  </aa>


以上xml里面的正确格式

现在如果要修改的话,我会先取出aa节点下面的值,然后直接提交就报错。
我用htmlspecialchars编码过,然后提交给xml节点后,虽然不报错,但是显示成下面错误的这样。
XML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><aa url="www.xxx.com">      </aa>


请问要提交含html标记的值给xml节点需要怎样处理下?

------解决方案--------------------
CDATA 中的内容不需要转义!转义反而错了

------解决方案--------------------
XML code
<aa url="www.xxx.com">           <font size="13"><a href="www.xxx.com?x=s&f=3" target="_blank">常 见 问 答1</a></font><br><br>       <font size="13"><a href="www.xxx.com?x=s&f=3" target="_blank">常 见 问 答2</a></font><br><br>       <font size="13"><a href="www.xxx.com?x=s&f=3" target="_blank">常 见 问 答3</a></font><br><br>      </aa><br><font color="#e78608">------解决方案--------------------</font><br>之后不要用htmlspecialchars编码<br><font color="#e78608">------解决方案--------------------</font><br>php.ini中 magic_quotes_gpc()函数是打开的么?自动给引号转义了。。<br><font color="#e78608">------解决方案--------------------</font><br>用XmlWriter写CDATA数据<br><font color="#e78608">------解决方案--------------------</font><br>顺便给你粘过来.
PHP code
$str = <url> </url><url> </url>XML;$xml = simplexml_load_string($str,'simpleXMLElement',LIBXML_NOCDATA);header('Content-type: application/xml');$xw = new XMLWriter();$xw->openMemory();$xw->startDocument('1.0','utf-8');$xw->startElement('root');foreach ($xml->url as $item){//在循环内修改即可    $xw->startElement('url');    $xw->writeCdata($item.'abc');    $xw->endElement();}$xw->endElement();$xw->endElement();echo $xw->outputMemory();<div class="clear">
                 
              
              
        
            </div>
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