1

I have a small problem with a script that reads an XML file and prints the output:

<?php

  $doc = new DOMDocument();
  $doc->load("http://www.tripadvisor.it/Feeds-d235955-treviews.xml");
  foreach ($doc->getElementsByTagName('item') as $node) {
      echo $node->getElementsByTagName('title')->item(0)->nodeValue;
      echo $node->getElementsByTagName('description')->item(0)->nodeValue;
      echo $node->getElementsByTagName('link')->item(0)->nodeValue;
      echo $node->getElementsByTagName('pubDate')->item(0)->nodeValue;
  }

?> 

If you use this script on my personal domain (hosting) it works fine, but if I use on my VPS does not work and returns these errors:

Warning: DOMDocument::load(http://www.tripadvisor.it/Feeds-d235955-treviews.xml) [domdocument.load]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/AAA/public_html/test.php on line 4
Warning: DOMDocument::load() [domdocument.load]: I/O warning : failed to load external entity "http://www.tripadvisor.it/Feeds-d235955-treviews.xml" in /home/AAA/public_html/test.php on line 4

Which PHP or APACHE settings that may cause problems?

Orezhon
  • 51
  • 4
  • 12

2 Answers2

2

As file_get_contents is not working in your server so try to use use curl to connect with tripadvisor server as below

<?php
$init = curl_init();
curl_setopt($init, CURLOPT_URL,'http://www.tripadvisor.it/Feeds-d235955-treviews.xml');
curl_setopt($init, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($init);
curl_close ($init);
$xml = simplexml_load_string($contents);
print"<pre>";
print_r($xml);
?>
Sanjeev Chauhan
  • 3,768
  • 3
  • 23
  • 29
  • I have this error if I use this script :"Warning: file_get_contents(http://www.tripadvisor.it/Feeds-d235955-treviews.xml) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/AAA/public_html/test.php on line 2" – Orezhon Jun 24 '11 at 13:08
  • As file_get_contents is not working in you server so try curl. I have updated my last answer please check – Sanjeev Chauhan Jun 24 '11 at 14:59
  • Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Space required after the Public Identifier in /home/AAA/public_html/test.php on line 7 Warning: simplexml_load_string() [function.simplexml-load-string]: in /home/AAA/public_html/test.php on line 7 – Orezhon Jun 25 '11 at 11:01
  • Check this problem here: http://stackoverflow.com/questions/2899274/php-simplexml-why-does-simplexml-load-string-fail-to-parse-google-weather-a – Sanjeev Chauhan Jun 25 '11 at 12:49
  • I think the problem is in settings VPS, no script works, because they can not read the file. is the header page 404. Which php or apache setting that may cause problems? – Orezhon Jun 27 '11 at 07:59
1

Try regular expression to get xml tags in php . Get xml with php curl then use regular expression. Try under following link http://www.bobulous.org.uk/coding/php-xml-regex.html

Thurein Soe
  • 178
  • 3
  • 8