-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClubRankings.php
96 lines (73 loc) · 2.02 KB
/
ClubRankings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
//Get page that contains the rankings
$fifaRankingsUrl = "http://www.uefa.com/memberassociations/uefarankings/club/index.html";
$response = file_get_contents($fifaRankingsUrl);
//Extract the numbers of teams in this list
preg_match ('/var lclubautosugg=new Array\(([0-9]*)\)/', $response, $match);
$numTeams = $match[1];
//Extract the piece that contains the rankings
preg_match ('/\<tbody>.*\<\/tbody\>/', $response, $match);
$rankingsBlob = $match[0];
//echo $rankingsBlob;
//Extract info on each team
//Club name
preg_match_all ('/title="([^"]{3,})"/', $rankingsBlob, $clubNames);
//Club Id
preg_match_all ('/\/([0-9]*)\.png/', $rankingsBlob, $clubIds);
//Club Country Code
preg_match_all ('/countrycode">([A-Z]{3})</', $rankingsBlob, $countryCodes);
$rankingDetails = array();
for($i=0; $i< $numTeams; $i++)
{
$clubName = $clubNames[1][$i];
$clubId = $clubIds[1][$i];
$countryCode = $countryCodes[1][$i];
//echo $team;
//$team = ascii_to_entities($team);
array_push($rankingDetails, array( "rank" => $i+1 ,
"clubName" => $clubName,
"clubId" => $clubId,
"countryCode" => $countryCode
));
}
//print_r ($rankingDetails);
echo json_encode($rankingDetails);
function ascii_to_entities($str)
{
$count = 1;
$out = '';
$temp = array();
for ($i = 0, $s = strlen($str); $i < $s; $i++)
{
$ordinal = ord($str[$i]);
if ($ordinal < 128)
{
if (count($temp) == 1)
{
$out .= '&#'.array_shift($temp).';';
$count = 1;
}
$out .= $str[$i];
}
else
{
if (count($temp) == 0)
{
$count = ($ordinal < 224) ? 2 : 3;
}
$temp[] = $ordinal;
if (count($temp) == $count)
{
$number = ($count == 3) ? (($temp['0'] % 16) * 4096) +
(($temp['1'] % 64) * 64) +
($temp['2'] % 64) : (($temp['0'] % 32) * 64) +
($temp['1'] % 64);
$out .= '&#'.$number.';';
$count = 1;
$temp = array();
}
}
}
return $out;
}
?>