I need a way to get only an element with a certain ID and display it with PHP. I am a PHP noob, so this has been very difficult so far. All the other questions similar to this were a bit too complicated, so I was wondering if someone could explain it to me.
To be more specific on what I want, I am making a spell search for a minecraft server. Our website is http://pvpzone.org/ and wiki is at http://pvpzone.wikispaces.com/. Each spell has a page on the wiki, like the one for “Vanish” is pvpzone.wikispaces.com/Vanish. The idea of the spell search would be an easier way to look for a spell, you type in the spell name and get the results. The div ‘wiki wikiPage’ has the spell data in it. I want to get just that div and display it. Sadly I can’t connect to any form of database with spells, it is hosted by Wikispaces and they don’t allow that.
I hope this has been clear, ask me for more details if you like. Here is what I have so far:
<?php
if(isset($_POST['submit']))
{
$spell=$_POST['spell'];
$pvpwiki="http://pvpzone.wikispaces.com/";
$site=$pvpwiki . $spell;
$submit=true;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Spell search</title>
</head>
<body>
<form name="spellsearch" id="spellsearchform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="spell" value="<?php if(!isset($_POST['submit'])){echo("Vanish");}?>"></input>
<input type="submit" value="Search" name="submit"></input>
</form>
<?php
$doc = new DomDocument;
$doc->validateOnParse = true;
$doc->loadHtml(file_get_contents($site));
var_dump($doc->getElementById('wiki wikiPage'));
if($doc == false && $submit)
{
echo("<br />" . "That is not a spell!");
}
?>
</body>
</html>
My problem right now is I am getting a parse error (Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: ID target_editor already defined in Entity, line: 212 in /home/content/d/e/x/dext0459/html/russellsayshi/phpspellsearch.php on line 24
NULL), I would really appreciate your help.
The error message you see is just a warning:
You can ignore those, they don’t stop you. If you see them on your website, you have not configured it properly, you should log errors, not display them.
Anyway in that case for that library you can disable them this way, too:
call it before loading the HTML. That HTML btw. didn’t cause the error when I tried with that website.
The next mistake is that you are looking for a class not for an ID. Look for the ID instead:
The whole code example:
Usage: