=)
[php]<?PHP
$nofile = 'RSItems'; // File to save as (no ext)
function SortIt($file) {
$content = file_get_contents('UnSorted' . $file . '.txt');
$fh = fopen($file . ".txt", 'a') or die("Can't open file");
for ($i = 0; $i <= 25000; $i++) {
if (preg_match('/^' . $i . ':\s+(?P<iname>.+)$/im', $content, $match)) {
fwrite($fh, $i . ': ' . $match['iname'] . "\r\n");
}
}
fclose($fh);
}
function GetIDs($letter, $page, $file) {
$pattern = '/<td><a href="http:\/\/services.runescape\.com\/m=itemdb_rs\/.+\/viewitem\.ws\?obj=(\d+)">(.+)<\/a><\/td>/i';
$url = "
http://services.runescape.com/m=itemdb_rs/results.ws?query=&sup=Initial%20Letter&cat=" . $letter . "&page=" . $page;
$contents = file_get_contents($url);
preg_match_all($pattern, $contents, $matches, PREG_PATTERN_ORDER);
$count = count($matches[1]);
$fh = fopen('UnSorted' . $file . '.txt', 'a') or die("Can't open file");
for ($i = 0; $i <= $count-1; $i++) {
fwrite($fh, $matches[1][$i] . ': ' . $matches[2][$i] . "\r\n");
}
fclose($fh);
}
function GetLastPage($letter) {
$url = "
http://services.runescape.com/m=itemdb_rs/results.ws?query=&sup=Initial%20Letter&cat=" . $letter . "&page=1";
$pattern = '/<a href="http:\/\/services\.runescape\.com\/m=itemdb_rs\/results\.ws\?query=&sup=Initial Letter&cat=.&sub=All&page=(.+)&vis=1&order=1&sortby=name&price=&members=">Last >><\/a>/';
$contents = file_get_contents($url);
preg_match($pattern, $contents, $matches);
return $matches[1];
}
$letters = Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Other');
echo "Getting List!\r\n";
for ($i = 0; $i <= 26; $i++) {
$lastpage = GetLastPage($letters[$i]);
for ($j = 1; $j <= $lastpage; $j++) {
echo 'Letter: ' . $letters[$i] . ' Page: ' . $j . "\r\n";
GetIDs($letters[$i], $j, $nofile);
}
}
echo "\r\nSorting List!\r\n";
SortIt($nofile);
echo "\r\n\r\nDone!\r\n";
?>[/php]