php读写标签 [英] php write and read tags
问题描述
我想用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 `<` instead of `<` and `>` instead of `>`
I have sort of rendering depends on `<`and `>` so when the change into `<` and `>` 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
<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>
推荐答案
fh = fopen(
fh = fopen(
fn,' wb');
fn, 'wb');
str =
str =
这篇关于php读写标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!