php读写标签 [英] php write and read tags

查看:77
本文介绍了php读写标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用DOMDocument解析器将标记写入.txt文件并读取它们,但是有时最后我得到的是`& lt而不是`<`和`& gt`而不是`>`

我有某种渲染方式取决于`<`和`>`,因此,当更改为`& lt``和`& gt;`时,它不匹配.但是在项目的其他部分,一切都很好(书写,阅读,渲染).


I want to write tags into .txt file with DOMDocument parser and read them but sometimes at the end I get `&lt;` instead of `<` and `&gt;` instead of `>`

I have sort of rendering depends on `<`and `>` so when the change into `&lt;` and `&gt;` it doesn''t match. but in a different part of the project everything is fine (writing, reading, rendering).

write

$fh = fopen($fn, 'wb');   $str = $this->saveXML($node);  fwrite($fh, $str );  fclose($fh);



其中$ fn是一个字符串,用于保存文件路径,而$ node是我正在浏览的树中的当前节点
阅读



where $fn is a string the holds the file path and the $node is the current node in the tree I''m navigating through
read

$fh = fopen($fn, 'rb');  $str = fread($fh, filesize($fn)); 
$renderer->doc .= $renderer->_xmlEntities($str);



样本输入



sample input

    <par><id>22</id><date>2012-04-10T14:53:06+02:00</date>
<P_title>title</P_title>
<P_body>
body
</P_body>
<keywords>keys</keywords>
</par>


导致页面源代码


result in page source

&lt;par&gt;&lt;id&gt;22&lt;/id&gt;&lt;date&gt;2012-04-10T14:53:06+02:00&lt;/date&gt;
&lt;P_title&gt;title&lt;/P_title&gt;
&lt;P_body&gt;
body
&lt;/P_body&gt;
&lt;keywords&gt;keys&lt;/keywords&gt;
&lt;/par&gt;

推荐答案

fh = fopen(
fh = fopen(


fn,' wb');
fn, 'wb');


str =
str =


这篇关于php读写标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆