【发布时间】:2014-11-26 21:44:32
【问题描述】:
我有一个大型 XML 文件,我想对其进行解析并放入数据库。比如这个文件:
<aa>
<bb>Some text goes here and <br /> some more on a new line
there are other <junk/> tags that I want to keep ignoring
</bb>
</aa>
我下面的代码使用 SimpleXML 来解析 bb 标记内的文本内容,但它默默地忽略了 <br /> 标记。如何修改我的代码以接受 <br/> 但不接受 <junk/>?
$xml = simplexml_load_file("ab.xml");
foreach( $xml->bb as $bb ) {
// $bb now contains the text content of the element, but no tags
}
【问题讨论】:
-
结果应该是:“有些文字放在这里,
在新行还有一些其他标签,我想继续忽略” -
好的,然后编辑剥离的值....
echo strip_tags($bb,"<br>");现在,它只保留<br>标签....试试吧,你会发现它会起作用。无论引号内的内容是什么,它都会保留并剥离任何其他标签。相信我!! -
当我运行我的代码时,$bb =
"Some text goes here and some more on a new line there are other tags that I want to keep ignoring"- 里面没有标签。 -
不,我将它保存在 MySQL 数据库中。我在查看某些数据的数据库条目时发现了这一点。