PHP 7 simpleXML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35593521/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP 7 simpleXML
提问by user101289
I'm testing PHP7, and have a weird issue after a recent update. SimpleXML should be enabled by default, and my phpinfo
page shows that it is available:
我正在测试 PHP7,最近更新后遇到了一个奇怪的问题。默认情况下应该启用 SimpleXML,我的phpinfo
页面显示它可用:
However, the functions are not available:
但是,以下功能不可用:
<?php
if (function_exists('simplexml_load_file')) {
echo "simpleXML functions are available.<br />\n";
} else {
echo "simpleXML functions are not available.<br />\n";
}
// result-- NOT available
And the module isn't listed as loaded:
并且该模块未列为已加载:
~ $ php -m
[PHP Modules]
calendar
Core
ctype
curl
...
Reflection
session
shmop
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
Zend OPcache
zlib
Anyone know if there's a workaround for this?
有谁知道是否有解决方法?
Version info:
版本信息:
~ $ php -v
PHP 7.0.3-8+deb.sury.org~trusty+2 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
回答by Alexandre Barbosa
I had the same problem and I'm using Ubuntu 15.10.
我遇到了同样的问题,我使用的是 Ubuntu 15.10。
In my case, to solve this issue, I installed the package php7.0-xml using the Synaptic package manager, which include SimpleXml. So, after restart my Apache server, my problem was solved. This package came in the Debian version and you can find it here: https://packages.debian.org/sid/php7.0-xml.
就我而言,为了解决这个问题,我使用 Synaptic 包管理器安装了 php7.0-xml 包,其中包括 SimpleXml。所以,重新启动我的 Apache 服务器后,我的问题就解决了。这个包是 Debian 版本,你可以在这里找到它:https: //packages.debian.org/sid/php7.0-xml。
回答by Flatron
For all those using Ubuntu with ppa:ondrej/php
PPA this will fix the problem:
对于所有使用带有ppa:ondrej/php
PPA 的Ubuntu 的人,这将解决问题:
apt install php7.0-mbstring php7.0-zip php7.0-xml
apt install php7.0-mbstring php7.0-zip php7.0-xml
(see https://launchpad.net/~ondrej/+archive/ubuntu/php)
(见https://launchpad.net/~ondrej/+archive/ubuntu/php)
Thanks @Alexandre Barbosa for pointing this out!
感谢@Alexandre Barbosa 指出这一点!
EDIT 20160423:
编辑 20160423:
One-liner to fix this issue:
One-liner 来解决这个问题:
sudo add-apt-repository -y ppa:ondrej/php && sudo apt update && sudo apt install -y php7.0-mbstring php7.0-zip php7.0-xml
(this will add the ppa noted above and will also make sure you always have the latest php. We use Ond?ej's PHP ppa for almost two years now and it's working like charm)
(这将添加上面提到的 ppa,并且还将确保您始终拥有最新的 php。我们现在使用 Ond?ej 的 PHP ppa 已经快两年了,它的工作非常有魅力)
回答by Deepak R
For Ubuntu 14.04 with
对于 Ubuntu 14.04
PHP 7.0.13-1+deb.sury.org~trusty+1 (cli) ( NTS )
PHP 7.0.13-1+deb.sury.org~trusty+1 (cli) ( NTS )
sudo apt-get install php-xml
worked for me.
为我工作。
回答by brismuth
For Alpine (in docker), you can use apk add php7-simplexml
.
对于 Alpine(在 docker 中),您可以使用apk add php7-simplexml
.
If that doesn't work for you, you can run apk add --no-cache php7-simplexml
. This is in case you aren't updating the package index first.
如果这对您不起作用,您可以运行apk add --no-cache php7-simplexml
. 这是为了防止您不先更新包索引。
回答by WebLuke
I'm using Bash on Windows (Ubuntu 16.04) and I just installed with php7.0-xml and all is working now for the Symfony 3.2.7 PHP requirements.
我在 Windows (Ubuntu 16.04) 上使用 Bash,我刚刚安装了 php7.0-xml,现在一切都可以满足 Symfony 3.2.7 PHP 要求。
sudo apt-get install php7.0-xml
回答by terwxqian
------------------in centos-------------------------
------------------在centos中-------------------------
find out which package provides php-xml:
找出哪个包提供了 php-xml:
yum provides php-xml
then from the output list,select the appropriate one, install
然后从输出列表中,选择合适的一个,安装
yum install php70u-xml-7.0.14-2.ius.centos7.x86_64
回答by BlueP
Had the same problem on AWS Linux 2, phpinfo() shows SimpleXML installed but not working, below cmd solved my issue
在 AWS Linux 2 上有同样的问题,phpinfo() 显示 SimpleXML 已安装但不工作,下面的 cmd 解决了我的问题
sudo yum install php-xml
回答by Mike Brant
Typically on Debian systems you have different PHP configuration for CLI and for PHP running as say an Apache module. Your phpinfo page may very well show simplexml as being enabled via web server, while it is not enabled via CLI.
通常在 Debian 系统上,您有不同的 PHP 配置,用于 CLI 和作为 Apache 模块运行的 PHP。您的 phpinfo 页面很可能将 simplexml 显示为通过 Web 服务器启用,而未通过 CLI 启用。