PHP: Call to undefined function: simplexml_load_string()

前端 未结 7 564
名媛妹妹
名媛妹妹 2020-12-13 23:02

I am implementing facebook count function using cron file. In which cron runs every 10 minutes and counts the total likes of a page.

for($i=0;$i<3;$i++){
         


        
相关标签:
7条回答
  • 2020-12-13 23:24

    For Nginx (without apache) and PHP 7.2, installing php7.2-xml wasn't enough. Had to install php7.2-simplexml package to get it to work

    So the commands for debian/ubuntu, update packages and install both packages

    apt update
    apt install php7.2-xml php7.2-simplexml
    

    And restart both Nginx and php

    systemctl restart nginx php7.2-fpm
    
    0 讨论(0)
  • 2020-12-13 23:29

    I also faced this issue. My Operating system is Ubuntu 18.04 and my PHP version is PHP 7.2.

    Here's how I solved it:

    Install Simplexml on your Ubuntu Server:

    sudo apt-get install php7.2-simplexml
    

    Restart Apache Server

    sudo systemctl restart apache2
    

    That's all.

    I hope this helps

    0 讨论(0)
  • 2020-12-13 23:29

    To fix this error on Centos 7:

    1. Install PHP extension:

      sudo yum install php-xml

    2. Restart your web server. In my case it's php-fpm:

      services php-fpm restart

    0 讨论(0)
  • 2020-12-13 23:34

    If the XML module is not installed, install it.

    Current version 5.6 on ubuntu 14.04:

    sudo apt-get install php5.6-xml
    

    And don't forget to run sudo service apache2 restart command after it

    Zulhilmi Zainudi

    0 讨论(0)
  • 2020-12-13 23:37

    Make sure that you have php-xml module installed and enabled in php.ini.

    You can also change response format to json which is easier to handle. In that case you have to only add &format=json to url query string.

    $rest_url = "http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls=".urlencode($source_url);
    

    And then use json_decode() to retrieve data in your script:

    $result = json_decode($content, true);
    $fb_like_count = $result['like_count'];
    
    0 讨论(0)
  • 2020-12-13 23:38

    I think it can be something like in this Post: Class 'SimpleXMLElement' not found on puphpet PHP 5.6 So maybe you could install/activate

    php-xml or php-simplexml
    

    Do not forget to activate the libraries in the php.ini file. (like the top comment)

    0 讨论(0)
提交回复
热议问题