gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:12:23 25 4
gpt4 key购买 nike

<?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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com