Let me put it into perspective for you, this is what two years of experience and practice does for you.
Old Script:
- Only works for specific values.
- Is actually broken and wont work under specific circumstances.
- Only works for game hub pages.
- Way more code then there needs to be.
- Just sucks, really, it sucks.
New Script:
- Works for all variables on a hub/members page, including newly added ones.
- Should work for all pages that have available text modes.
- Works on both members and game hub pages.
- Aforementioned improvements require less code than the original script.
- A way bigger improvement over the old.
- A (hacky) method to make sure it doesn't attempt to parse pages that aren't text.
Just to give you a demonstration of how it works, he's the outputted array on a few pages:
- Icon Ultima's Hub Page
- Dragonball Online II Hub
- Lummox JR's Member Page
- Lummox JR's Member Page Extended
- My Members Page
- My Members Page Extended
And so on and so forth.
The only annoying part of the function is something I was struggling to figure out. I honestly couldn't find a way to check the Content-Type of the page with fopen() or file_get_contents() (if someone knows a way, fill me in!), so I've resorted to actually loading the page twice, one for it's headers, and if it's a text/plain page, continue on to get the content, otherwise return false.
So then, here's a PHP alternative to getting game info off the BYOND hub:
<?
echo "<pre>" . print_r(parse_hub("tiberath", "true", "long=true;num_posts=10"), TRUE) . "</pre>";
function parse_hub($hub, $member=FALSE, $additional = null) {
$url = "http://www.byond.com/" . ($member ? "members" : "hub") . "/" . $hub . ";format=text" . ($additional ? ";" . $additional : null);
$page = get_headers($url, TRUE);
if(strpos($page["Content-Type"], "text/plain") === false) return false;
$return_array = array(); // Array returned. Duh.
$page = file_get_contents($url);
$page = explode(chr(10), htmlentities($page, ENT_NOQUOTES));
$heading = "";
$subheading = "";
foreach($page as $p) {
if(!strpos($p, "=")) {
if(strpos($p, "/")) {
$p = explode("/", $p);
$heading = trim($p[0]);
$subheading = trim($p[1]);
} else {
$heading = trim($p);
unset($subheading);
}
} else {
$start = strpos($p, "=");
$a = substr($p, 0, $start);
$b = substr($p, $start + 2);
if(strpos($b, "list") === 0) {
$b = str_replace("\"", "", substr($b, 5, strlen($b) - 7));
$b = explode(",", $b);
if(!$b[0]) $b = null;
}
if($subheading) {
$return_array[$heading][$subheading][trim($a)] = ((strpos($b, "\"") === 0) ? substr($b, 1, strlen($b) - 3) : $b);
} else {
$return_array[$heading][trim($a)] = ((strpos($b, "\"") === 0) ? substr($b, 1, strlen($b) - 3) : $b);
}
}
}
return $return_array;
}
?>
Also note: Although the text-mode of the hub uses the same format as a plain-text BYOND Savefile. That function will fail miserably if it attempts to read one. I never designed it for use with a savefile, only for use with the BYOND Hub. If the hub is updated to include a directory inside a directory, then is when I'll have to make it completely compliant with a BYOND Savefile.
Also, also note: I'll be working on a function to read a BYOND Savefile (and thus put this one out of business), but I'm not entirely sure whether or not I'll release that one. Gotta keep some tricks for myself, you know.
Yeah, I was bored today.
Seriously though, not to be insulting in any way. What is the purpose of this creation?