<?php
for ($x = 0; $x <= 150; $x++) {
$url = "https://www.game-state.com/index.php?page=$x&game=cs&passworded=1&spp=50";
$raw = file_get_contents($url);
$startsAt = strpos($raw, "serverlist") + strlen(">");
$endsAt = strpos($raw, "paginate", $startsAt);
$result = substr($raw, $startsAt, $endsAt - $startsAt);
preg_match_all("'<td>(.*?)</td>'si", $result, $matches);
$var1 = $matches[1];
print_r($var1);
}
?>
<?php
function filterUnwantedValues($input) {
$unwantedValues = [
'Server Name',
'Players',
'Map',
];
foreach ($unwantedValues as $value) {
// Use !== false because strpos might return 0
if (strpos($input, $value) !== false) {
return false;
}
}
return true;
}
function fetchData($start = 1, $stop = 1, $currentValues = []) {
if ($stop > 0 && $start > $stop) {
return $currentValues;
}
$url = "https://www.game-state.com/index.php?page=$start&game=cs&passworded=1&spp=50";
$data = file_get_contents($url);
preg_match_all(
'/<td class="(hostname|players|mapname)">(.+)<\/td>/i',
$data,
$matches
);
if (!isset($matches[2])) {
return $currentValues;
}
$filteredValues = array_filter($matches[2], 'filterUnwantedValues');
if (!count($filteredValues)) {
return $currentValues;
}
return fetchData(
$start + 1,
$stop,
array_merge($currentValues, $filteredValues)
);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php
$start = isset($_GET['start']) ? $_GET['start'] : 1;
$stop = isset($_GET['stop']) ? $_GET['stop'] : $start;
foreach (fetchData($start, $stop) as $key => $value) {
// Number of class names in preg_match_all pattern = 3
if ($key !== 0 && $key % 3 === 0) {
echo '<br>';
}
echo '<div>', strip_tags($value), '</div>';
}
?>
</body>
</html>
Flashback finansieras genom donationer från våra medlemmar och besökare. Det är med hjälp av dig vi kan fortsätta erbjuda en fri samhällsdebatt. Tack för ditt stöd!
Swish: 123 536 99 96 Bankgiro: 211-4106
Flashback finansieras genom donationer från våra medlemmar och besökare. Det är med hjälp av dig vi kan fortsätta erbjuda en fri samhällsdebatt. Tack för ditt stöd!
Swish: 123 536 99 96 Bankgiro: 211-4106