views:

23

answers:

1

Hi all.

The code pasted below, works on my PC, but not on my hosting (which have PHP 5.2.13 installed).

$source = file_get_contents('http://example.com/example', 0);
$dom = new DOMDocument;
@$dom->loadHTML($source);
$dom->preserveWhiteSpace = false;

$xpath = new DOMXPath($dom);
$tags = $xpath->query('//div[@class="item"]');

$xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n<root>\r\n";

foreach($tags as $tag)
    $xml .= "\t<tag>" . trim($tag->nodeValue) . "</tag>\r\n";

$xml .= '</root>';

$xml_file = 'tags.xml';
$fopen_handle = fopen($xml_file, 'w+');
fwrite($fopen_handle, $xml);
fclose($fopen_handle);

On my hosting, the foreach loop doesn't executes i.e. I get only this in the XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
</root>

Thanks in advance.

A: 

Your hosting doesn't support file_get_contents (allow_url_fopen is the setting iirc)

Try this:

$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, 'http://example.com');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch); 
Snake
Thank you very much Snake.Thumb down for http://www.m2host.com
Filip Nikoloski