- file_get_contents: documentation ( source)
- strpos: documentation ( source)
- json_decode: documentation ( source)
- str_replace: documentation ( source)
- key: documentation ( source)
<?php
$contents_request = "http://en.wikipedia.org/w/api.php?format=json&action=parse&page=Enter%20Sandman";
$contents_response = file_get_contents($contents_request);
$contents_jsonobj = json_decode($contents_response);
$key = key($contents_jsonobj->parse->text);
$wikitext = $contents_jsonobj->parse->text->$key;
$wiki_html = str_replace("<a href=\"/","<a target=\"_blank\" href=\"http://en.wikipedia.org/", $wikitext);
$toc = strpos("toc", $wiki_html);
echo $toc;
?>