Orginalny plik wyglada nastepujaco :
Kod
<?php
class spTibCharacter {
const ATTEMPTS = 5;
const TIMEOUT = 30; // seconds
static function getCharacter($names) {
$table = array();
do {
if (!function_exists('curl_multi_init')) {
error_log('spTibCharacter requires the cURL PHP extension');
return false;
}
$mh = curl_multi_init();
$chs = array();
foreach ($names as $name) {
$chs[$name] = curl_init();
curl_setopt($chs[$name], CURLOPT_URL, $url = sprintf('http://www.tibia.com/community/?subtopic=characters&name=%s', urlencode($name)));
curl_setopt($chs[$name], CURLOPT_RETURNTRANSFER, true);
curl_setopt($chs[$name], CURLOPT_FRESH_CONNECT, true);
curl_setopt($chs[$name], CURLOPT_TIMEOUT, self::TIMEOUT);
curl_multi_add_handle($mh, $chs[$name]);
if (@$GLOBALS['debug']) { error_log("preparing to fetch $url"); }
}
do {
$mrc = curl_multi_exec($mh, $active);
} while ($active);
foreach ($names as $name) {
$out = curl_multi_getcontent($chs[$name]);
curl_close($chs[$name]);
$failure = false;
if (preg_match('@<TR><TD BGCOLOR="#505050" CLASS=white><B>Could not find character</B></TD></TR>@s', $out)) {
$table[$name] = array('error' => 'Could not find character');
}
else if (preg_match('@<TD WIDTH=20%>Name:</TD><TD>(.+?)</TD></TR>@s', $out, $m))
{
if (preg_match('@<TD.*?CLASS=red>Banished:</TD><TD CLASS=red>until .*? because of using unofficial software to play</TD>@s', $out)) {
$table[$name]['banished'] = 'unofficial_software';
}
if( preg_match("#<TD>Level:</TD><TD>(\d{1,3})</TD>#",$out,$lvl)){
if (preg_match("#<TD>Account&\#160;Status:</TD><TD>(Free Account|Premium Account)#",$out,$account)){
if(preg_match("@<TD>Sex:</TD><TD>((?:fe|)male)</TD>@is", $out, $sex)){
if(preg_match("@<TD>Profession:</TD><TD>([^<]+)?</TD></TR>@is", $out, $voc)){
if(preg_match("@<TD>World:</TD><TD>(.+?)</TD></TR>@is", $out, $world)){
if( preg_match("@<TD>Residence:</TD><TD>(.+?)</TD>@is", $out, $residence)){
$table[$name] = array('name' => $m[1], 'level' => $lvl[1], 'acc_status' => $account[1], 'sex' => $sex[1], 'voc' => $voc[1], 'world' => $world[1], 'residence' => $residence[1]);
}
}
}
}
}
}
}
else {
$table[$name] = array('error' => 'Unknown error');
}
}
curl_multi_close($mh);
} while (0);
return $table;
}
}
print_r($table);
?>
Jak mozna zauwazyc odczyt klasy odbywa się w prosty sposób poprzez $variable = TibiaWebsite::characterInfo('Name');