Codice PHP:
function content($page){
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_URL, $page);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
if ($result) {
return $result;
} else {
return curl_error($ch);
}
}
/* Connessione e selezione del database */
/* caricamento ally */
$page = "http://it1.tribals.it/map/ally.txt";
$numt=0;
$delete="TRUNCATE TABLE tw_ally";
mysql_query($delete);
$txt = content($page);
$lines = explode("\n", $txt);
if(!is_array($lines)) die("Non è stato possibile aprire il file");
foreach($lines as $line) {
list($id, $name, $tag, $members, $villages, $points, $all_points, $rank) = explode(',', $line);
$name = urldecode($name);
$name = addslashes($name);
$tag = urldecode($tag);
$tag = addslashes($tag);
$query = "INSERT INTO tw_ally VALUES ('$id', '$name', '$tag', '$members', '$villages', '$points', '$all_points', '$rank')";
mysql_query($query);
$numt=$numt+1;
}
/* caricamento giocatori */
$page = "http://it1.tribals.it/map/player.txt";
$numg=0;
$delete="TRUNCATE TABLE tw_player";
mysql_query($delete);
$txt = content($page);
$lines = explode("\n", $txt);
if(!is_array($lines)) die("Non è stato possibile aprire il file");
foreach($lines as $line) {
list($id, $name, $ally, $villages, $points, $rank) = explode(',', $line);
$name = urldecode($name);
$name = addslashes($name);
$query = "INSERT INTO tw_player VALUES ('$id', '$name', '$ally', '$villages', '$points', '$rank', '0')";
mysql_query($query);
$numg=$numg+1;
}
/* caricamento villi */
$page = "http://it1.tribals.it/map/village.txt";
$numv=0;
$delete="TRUNCATE TABLE tw_village";
mysql_query($delete);
$txt = content($page);
$lines = explode("\n", $txt);
if(!is_array($lines)) die("Non è stato possibile aprire il file");
foreach($lines as $line) {
list($id, $name, $x, $y, $player, $points, $bonus) = explode(',', $line);
$name = urldecode($name);
$name = addslashes($name);
$query = "INSERT INTO tw_village VALUES ('$id', '$name', '$x', '$y', '$player', '$points', '$bonus')";
mysql_query($query);
$numv=$numv+1;
}
echo $numv." villi, ".$numt." ally e ".$numg." giocatori caricati.";
/* Chiusura della connessione */
Qualcuno sa dirmi perkè non funziona con i file "village.txt" e "player.txt"?