2010-10-11 4 views
1

Le code collé ci-dessous, fonctionne sur mon PC, mais pas sur mon hébergement (qui ont PHP 5.2.13 installé).Problème PHP avec DOM analyse

$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); 

Sur mon hébergement, la boucle foreach ne exécute dire que je ne reçois que ce dans le fichier XML:

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

Merci à l'avance.

+1

Cela appelle pour le débogage de base. Que fait un 'error_reporting (E_ALL); –

Répondre

0

Votre hébergement ne supporte pas file_get_contents (allow_url_fopen est le réglage IIRC)

Essayez ceci:

$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); 
+0

Merci beaucoup Snake. Le pouce vers le bas pour http://www.m2host.com –