【问题标题】:Trouble with PHP loading and parsing XMLPHP 加载和解析 XML 的问题
【发布时间】:2014-06-12 14:28:15
【问题描述】:

您好,我有这样的 XML 文件:

<?xml version="1.0" ?>
<songs>
    <song dateplayed="2011-07-24 19:40:26">
        <title>I left my heart on Europa</title>
        <artist>Ship of Nomads</artist>
    </song>
    <song dateplayed="2011-07-24 19:27:42">
        <title>Oh Ganymede</title>
        <artist>Beefachanga</artist>
    </song>
    <song dateplayed="2011-07-24 19:23:50">
        <title>Kallichore</title>
        <artist>Jewitt K. Sheppard</artist>
    </song>
</songs>

然后是我的 HTML 文档:

<html>
<body>

<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>

<?php
    $mysongs = simplexml_load_file('songs.xml');
    echo $mysongs->song[0]->artist;?>


</body>
</html> 

但是,当我开始运行页面时,我得到了这个:

通常我在这里做错了什么?看到 PHP 如何不显示艺术家,我是否需要包含一个库等? xml文件和html文件在同一个文件夹中。

【问题讨论】:

  • and then my HTML Document: 在 .html 中?有你的问题:)
  • 做一个view source。你可能会在那里看到所有的 php 代码。

标签: php html xml


【解决方案1】:

将文件重命名为index.php。假设您已正确安装 PHP,Web 服务器将根据文档的文件扩展名决定该文档是否应由 PHP 处理。默认情况下,这是 *.php 文档,但不是 *.html 文档。

【讨论】:

  • 您好,我没有安装 php,也没有在 Web 服务器上安装,通常我是通过浏览器完成的
  • 如果你想运行 PHP,你需要安装一个网络服务器,比如 WAMP 堆栈 (Windows),你不能通过file:// 协议运行它。
  • @CatLikeOlive0 这不起作用。您需要安装 Web 服务器和 PHP。
【解决方案2】:

您似乎在未执行 PHP 的服务器上运行此程序。要么,要么你的文件没有 PHP 扩展,所以你的服务器不知道执行 PHP。这就是你得到原始文本的原因。

【讨论】:

    猜你喜欢
    • 2013-05-20
    • 1970-01-01
    • 2015-05-11
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    相关资源
    最近更新 更多