可能重复:
A simple program to CRUD node and node values of xml file
我有一个.XML文件,显示了20个最新的工作, 任何人都可以展示如何将.xml文件中的数据显示为.php文件(没有javascript),我可以在其中设置输出样式吗?
<?xml version="1.0" encoding="utf-8"?>
<jobfeed>
<job>
<logo>http://google.com/logo.png</logo>
<Firmname>Google</Firmname>
<description> Pellentesque habitant morbi tristique senectus et netus.</description>
<title>CEO</title>
<location>London</location>
<date>1. December</date>
<link>http://www.google.com/jobs</link>
</job>
<job>
<logo>http://google.com/logo.png</logo>
<Firmname>Google</Firmname>
<description> Pellentesque habitant morbi tristique senectus et netus.</description>
<title>CEO</title>
<location>London</location>
<date>1. December</date>
<link>http://www.google.com/jobs</link>
</job>
</jobfeed>
答案 0 :(得分:0)
您可以使用simplexml来解析XML并输出所需的HTML标记。
<?php
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<jobfeed>
<job>
<logo>http://google.com/logo.png</logo>
<Firmname>Google</Firmname>
<description> Pellentesque habitant morbi tristique senectus et netus.</description>
<title>CEO</title>
<location>London</location>
<date>1. December</date>
<link>http://www.google.com/jobs</link>
</job>
<job>
<logo>http://google.com/logo.png</logo>
<Firmname>Google</Firmname>
<description> Pellentesque habitant morbi tristique senectus et netus.</description>
<title>CEO</title>
<location>London</location>
<date>1. December</date>
<link>http://www.google.com/jobs</link>
</job>
</jobfeed>
XML;
$xml = simplexml_load_string($xml);
foreach($xml as $job) {
?>
<div>
<div class="tb"><img scr="<?php echo $job->logo ?>"/>
etc ...
</div>
<?php } ?>