Advertisement
austinh115

[UPDATED] xat wiki error grabber

Oct 25th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2. $json = json_decode(file_get_contents("http://util.xat.com/wiki/api.php?action=query&titles=Errors&prop=revisions&rvprop=content&format=json"), true);
  3. $wiki = strip_tags($json['query']['pages'][156]['revisions'][0]['*']);
  4. $splits = preg_split("/\n?==\s?(.*?)\s?==\n?/", $wiki, -1, PREG_SPLIT_DELIM_CAPTURE);
  5. array_shift($splits);
  6. $categories = [];
  7. for($x = 0; $x < count($splits); $x+=2) {
  8.     preg_match_all("/{{(?:spoiler\|bold=no\|\n)(.*?)}}/s", trim($splits[$x+1]), $m);
  9.     $categories[$splits[$x]] = array_map(function($element) {
  10.         $element = str_replace("  ", " ", $element);
  11.         $element = preg_replace(["/\[\[(\w+)\]\]/", "/\[\[(?:.*?)\|(.*?)\]\]/", "/\[(.*?)\s(?:.*?)\]/"], ["http://xat.wiki/$1", "$1", "$1"], $element);
  12.         $element = explode("|", $element, 2);
  13.         if(count($element) > 1)
  14.         $element[0] .= " More information at http://xat.wiki/Errors.";
  15.         return array_map("trim", $element);
  16.     }, $m[1]);
  17. }
  18. print_r($categories);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement