<?php $Wiki = simplexml_load_file('http://fr.wikipedia.org/w/api.php?action=query&list=random&rnnamespace=0&rnlimit=1&format=xml'); ?>
<?php ini_set('user_agent', 'Mozilla/5.0 (X11; U; GNU Hurd; C -) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.10.1'); $Wiki = simplexml_load_file('http://fr.wikipedia.org/w/api.php?action=query&list=random&rnnamespace=0&rnlimit=1&format=xml'); ?>
$Wiki->query->random->page['title']
<?php ini_set('user_agent', 'Mozilla/5.0 (X11; U; GNU Hurd; C -) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.10.1'); $Wiki = simplexml_load_file('http://fr.wikipedia.org/w/api.php?action=query&list=random&rnnamespace=0&rnlimit=1&format=xml'); var_dump((string)$Wiki->query->random->page['title']); $link = 'http://fr.wikipedia.org/wiki/' . urlencode(str_replace(' ', '_', $Wiki->query->random->page['title'])); var_dump($link); ?>
tycho@uraniborg-> php toto.php
string(8) "BB 27000"
string(37) "http://fr.wikipedia.org/wiki/BB_27000"
tycho@uraniborg-> php toto.php
string(17) "Palestine (Texas)"
string(50) "http://fr.wikipedia.org/wiki/Palestine_%28Texas%29"
tycho@uraniborg-> php toto.php
string(47) "Parcours du Tours Volley-Ball en coupe d'Europe"
string(78) "http://fr.wikipedia.org/wiki/Parcours_du_Tours_Volley-Ball_en_coupe_d%27Europe"
<?php if (file_exists("http://en.wikipedia.org/w/api.php?action=query&list=random&rnnamespace=0&rnlimit=2&format=xml")) { $xml = simplexml_load_file('test.xml'); print_r($xml); } else { exit('Echec lors de l\'ouverture du fichier test.xml.'); } ?>
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question<?php //1ere tentative /*if (file_exists("http://en.wikipedia.org/w/api.php?action=query&list=random&rnnamespace=0&rnlimit=2&format=xml")) { $xml = simplexml_load_file("http://en.wikipedia.org/w/api.php?action=query&list=random&rnnamespace=0&rnlimit=2&format=xml"); print_r($xml); } else { exit('Echec lors de l\'ouverture du fichier test.xml.'); }*/ //2ème /* $Url = "http://en.wikipedia.org/w/api.php?action=query&list=random&rnnamespace=0&rnlimit=2&format=xml"; $file = file_get_contents($Url); $xml = simplexml_load_string($file); echo ''; print_r($xml); echo ' '; */ // troisième, pour tester file_get_contents() (fonctionne) $homepage = file_get_contents('http://en.wikipedia.org/wiki/Main_Page'); echo $homepage; ?>