Reputation: 19
i am trying go get content of certain div
the html structure is something like this:
<div id="event-pane" class="class1">
<div id="e170923" class="class2">
<div id="e170948" class="class2">
<div id="e170923" class="class2">
i am trying to get the div its id="exxxxxx"
while xxxxxx is $event_id
i am using file_get_contants and DOM here is my code:
<?php
$event_id = $_GET['eventId'];
//Get the url
$url = "static/section35.html";
$html = file_get_contents($url);
$doc = new DOMDocument(); // create DOMDocument
libxml_use_internal_errors(true);
$doc->loadHTML($html); // load HTML you can add $html
if($html) {
$divs = $doc->getElementById('e. $event_id, 0');
$elements = $doc->getElementsByTagName('tbody');
$toRemove = array();
// gather a list of tbodys to remove
foreach($elements as $el)
if((strpos($el->nodeValue, 'desktop') !== false) && !in_array($el->parentNode, $toRemove, true))
$toRemove[] = $el->parentNode;
foreach($elements as $el)
if((strpos($el->nodeValue, 'Recommended') !== false) && !in_array($el->parentNode, $toRemove, true))
$toRemove[] = $el->parentNode;
// remove them
foreach($toRemove as $tbody)
$tbody->parentNode->removeChild($tbody);
echo str_replace(array('style="display: none;','</h3><table','http://www.drakulastream.eu'),array('', '<table',''),$doc->saveHTML());
}
else {
echo "<center><h3 style='color:#003366;'>There are no events today</h3></center>";
}
?>
i don't know what is wrong with code
Upvotes: 0
Views: 3817
Reputation: 102793
It looks like you've just mis-typed the selector. Should be like this:
$divs = $doc->getElementById('e' . $event_id);
Upvotes: 1