【问题标题】:Uncaught Error: Class 'SimpleXMLElement' not found未捕获的错误:找不到类“SimpleXMLElement”
【发布时间】:2020-11-10 18:31:40
【问题描述】:

SimpleXMLElement 不起作用!

检查 php -v:

PHP 7.4.8 (cli) (built: Jul 13 2020 16:45:28) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.8, Copyright (c), by Zend Technologies

php -m:

php -m
[PHP Modules]
...
SimpleXML
..
xml
xmlreader
xmlwriter
xsl
...

我用的是PHP 7.2,安装了php-xml、php-simplexml等

日志:

PHP Fatal error:  Uncaught Error: Class 'SimpleXMLElement' not found in /var/www/html/inc/functions.php:828

php:

 $myCurl = curl_init();
  curl_setopt_array($myCurl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => http_build_query(array($body))
  ));
  $response = curl_exec($myCurl);
  curl_close($myCurl);
  
$robo_response = new SimpleXMLElement($response);

【问题讨论】:

  • 尝试以下操作:$robo_response = new \SimpleXMLElement($response);
  • 我在尝试。我也有错误。
  • 您已经共享了命令行配置,但您运行的是/var/www/html 形式的代码,这暗示了一个Web 服务器。能否请您确认一下您的环境是什么?
  • 我也面临同样的问题。它在本地运行良好(win)在实时服务器上运行良好(Azure ubuntu)

标签: php simplexml php-7


【解决方案1】:

在我的 Ubuntu 上启用了 PHP7.0。需要 PHP 7.4

sudo a2dismod php7.0
sudo a2enmod php7.4
sudo service apache2 restart

谢谢大家的帮助。

【讨论】:

    猜你喜欢
    • 2020-10-02
    • 2021-12-03
    • 2020-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-23
    • 2019-04-14
    相关资源
    最近更新 更多