php - 在 PHP 中使用 SimpleXml 函数时,XML 文件内容未显示在 apache2 本地主机上

标签 php xml linux apache ubuntu

<?php
$bookxml =simplexml_load_file("book.xml");

print_r($bookxml);  
echo"Display this";

?>

xml文件

<xml version="1.0" encoding="UTF-8">
<book>
    <bookcode>COMPUTER</bookcode>
    <bookname>LEARN PHP</bookname>
    <bookauthor>Balguruswamy</bookauthor>
    <publisher>Arihant</publisher>
    <price>645.50</price>
</book>
<book>
    <bookcode>Maths</bookcode>
    <bookname>Solve Trig</bookname>
    <bookauthor>A.B.C</bookauthor>
    <publisher>TM</publisher>
    <price>150.42</price>
</book>
<book>
    <bookcode>English</bookcode>
    <bookname>Prose</bookname>
    <bookauthor>D .E.EF</bookauthor>
    <publisher>Vision</publisher>
    <price>64.65</price>
</book>
<book>
    <bookcode>COMPUTER</bookcode>
    <bookname>LEARN JAVA</bookname>
    <bookauthor>Balguruswamy</bookauthor>
    <publisher>Penguin</publisher>
    <price>424.9</price>
</book>


当我在终端中使用 php filename.php 运行 php 脚本时,我可以看到 xml 文件,但是当我尝试从我的浏览器上的 apache localhost 执行时,我看不到它。我该怎么办?

编辑:

当我打开 apache2 的错误日志时,我看到了这个。

[Sun Jan 28 10:35:16.301835 2018] [mpm_event:notice] [pid 9407:tid 140581351434112] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations [Sun Jan 28 10:35:16.301914 2018] [core:notice] [pid 9407:tid 140581351434112] AH00094: Command line: '/usr/sbin/apache2' [Sun Jan 28 10:47:21.326245 2018] [mpm_event:notice] [pid 9407:tid 140581351434112] AH00491: caught SIGTERM, shutting down [Sun Jan 28 10:47:22.379645 2018] [mpm_event:notice] [pid 10070:tid 139652613879680] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations [Sun Jan 28 10:47:22.379716 2018] [core:notice] [pid 10070:tid 139652613879680] AH00094: Command line: '/usr/sbin/apache2' [Sun Jan 28 10:47:25.835120 2018] [mpm_event:notice] [pid 10070:tid 139652613879680] AH00491: caught SIGTERM, shutting down [Sun Jan 28 10:47:26.887422 2018] [mpm_event:notice] [pid 10176:tid 140391800403840] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations [Sun Jan 28 10:47:26.887537 2018] [core:notice] [pid 10176:tid 140391800403840] AH00094: Command line: '/usr/sbin/apache2' [Sun Jan 28 10:47:30.516640 2018] [authz_core:error] [pid 10179:tid 140391718758144] [client 127.0.0.1:49064] AH01630: client denied by server configuration: /home/pushkarrao/Work/apachetrue/ [Sun Jan 28 10:47:30.631338 2018] [authz_core:error] [pid 10179:tid 140391701972736] [client 127.0.0.1:49064] AH01630: client denied by server configuration: /home/pushkarrao/Work/apachetrue/favicon.ico [Sun Jan 28 10:47:30.794247 2018] [authz_core:error] [pid 10179:tid 140391710365440] [client 127.0.0.1:49064] AH01630: client denied by server configuration: /home/pushkarrao/Work/apachetrue/favicon.ico [Sun Jan 28 10:53:03.602646 2018] [mpm_event:notice] [pid 10176:tid 140391800403840] AH00491: caught SIGTERM, shutting down [Sun Jan 28 10:53:04.686297 2018] [mpm_event:notice] [pid 10534:tid 139701054691200] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations [Sun Jan 28 10:53:04.686390 2018] [core:notice] [pid 10534:tid 139701054691200] AH00094: Command line: '/usr/sbin/apache2' [Sun Jan 28 19:41:28.732489 2018] [mpm_event:notice] [pid 10534:tid 139701054691200] AH00491: caught SIGTERM, shutting down [Sun Jan 28 19:41:29.794682 2018] [mpm_event:notice] [pid 13440:tid 139628059764608] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations [Sun Jan 28 19:41:29.794753 2018] [core:notice] [pid 13440:tid 139628059764608] AH00094: Command line: '/usr/sbin/apache2'

最佳答案

我认为您的 xml 结构不正确:

应该是这样的:

<?xml version="1.0" encoding="utf-8"?>
<books>
 <book>
    <bookcode>COMPUTER</bookcode>
    <bookname>LEARN PHP</bookname>
    <bookauthor>Balguruswamy</bookauthor>
    <publisher>Arihant</publisher>
    <price>645.50</price>
</book>
<book>
    <bookcode>Maths</bookcode>
    <bookname>Solve Trig</bookname>
    <bookauthor>A.B.C</bookauthor>
    <publisher>TM</publisher>
    <price>150.42</price>
</book>
<book>
    <bookcode>English</bookcode>
    <bookname>Prose</bookname>
    <bookauthor>D .E.EF</bookauthor>
    <publisher>Vision</publisher>
    <price>64.65</price>
</book>
<book>
    <bookcode>COMPUTER</bookcode>
    <bookname>LEARN JAVA</bookname>
    <bookauthor>Balguruswamy</bookauthor>
    <publisher>Penguin</publisher>
    <price>424.9</price>
</book>
</books>

获取 xml 元素的 PHP 代码:

<?php
     $bookxml =simplexml_load_file("book.xml");
     echo '<pre>';
     print_r($bookxml);
?>

关于php - 在 PHP 中使用 SimpleXml 函数时,XML 文件内容未显示在 apache2 本地主机上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48494174/

相关文章:

php - 以两列显示记录

php - 在目录 View Woocommerce 上显示 "Out of Stock "

php - 多个 CREATE TABLE 在一个事务中有错误 - 没有 PDO 异常

linux - 从/proc/$PID/smaps 读取很慢

php - 更新数组中的项目

xml - 使用 xslt 比较两个 xml 文件

python - 使用 Python 操作 XML

ruby - 如何使用 Nokogiri 使空标签自动关闭?

linux - 使用 xinit 控制非 x 实用程序的放置

.net - 我需要在每台 Linux PC 上安装 mono 才能在 Linux 平台上运行 .NET 应用程序吗?