DOMDocument-> loadXML () error

Hello,

This line gives an error; $this->page->loadXML($this->getXML());
Where’s the error?

class Doviz {

private $page, $currencies;

public function __construct(){

    

    $this->page = new DOMDocument;

    $this->page->loadXML($this->getXML());

    $this->currencies = array();

    $this->initCurrencies();

    return $this;

    

}

private function getXML(){

        if (isset($_SERVER['HTTPS']) &&

        ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||

        isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&

        $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {

            $xmlURL = 'https://www.tcmb.gov.tr/kurlar/today.xml';

        }

        else {

            $xmlURL = 'http://www.tcmb.gov.tr/kurlar/today.xml';

        }

               

    if(function_exists('curl_version')){

        $ch = curl_init();

        curl_setopt_array($ch, 

            array(

                CURLOPT_RETURNTRANSFER => 1,

                CURLOPT_URL    => $xmlURL

            )

        );

        $xmlPage = curl_exec($ch);

        curl_close($ch);

    }

    else{

        $xmlPage = file_get_contents($xmlURL);

    }

    return $xmlPage;

    

}

We really shouldn’t have to guess what the error is. How about you just tell us what it is?

There’s more code…
To take the current exchange rate of the Central Bank of the Republic of Turkey
Does it look like a mistake here?

You aren’t telling us an error or giving any idea of an issue. All I can really see is you have way to many conditions in your getXML function when you could just do this,

class Doviz {

private $page, $currencies;
private $_xml;

public function __construct(){
    $this->_xml = file_get_contents('https://www.tcmb.gov.tr/kurlar/today.xml');
    $this->page = new DOMDocument;
    $this->page->loadXML($this->getXML());
    $this->currencies = array();
    $this->initCurrencies();
}

private function getXML(){
    return $this->_xml;
}

Though ideally that url would not be hardcoded so that it could be used for other pages as well.

It works on the real server
However, it does not work on the local server
Now it worked on the local server
There are no errors in the php_error.log file
Thank you so much

There’s been a change.
Previously “allow_url_fopen” did not have to be turned on.
Now works if “allow_url_fopen” is on

Sponsor our Newsletter | Privacy Policy | Terms of Service