Demonic Posted September 26, 2008 Share Posted September 26, 2008 I have a basic call to all the "h3" html tags in the html, yet I'm unsure how to get the element next to it in the dom tree. I have the following: $doc = new DOMDocument(); @$doc->loadHTML($html); $items = $doc->getElementsByTagName("h3"); for ($i = 0; $i < $items->length; $i++) { echo $items->item($i)->nodeValue . "\n"; } How would I get the next sibling of the current element in the array. Its sorta layed out like this: <h3></h3> <div></div> I want to get that div tag right after the h3, is this possible, and if it is how do I do it with what I currently have? Link to comment https://forums.phpfreaks.com/topic/126002-working-with-siblings-and-php-dom-question/ Share on other sites More sharing options...
F1Fan Posted September 26, 2008 Share Posted September 26, 2008 Do you mean that it's doing this: This is your H3 stuff... This is your DIV stuff... and you want it to look like this: This is your H3 stuff...This is your DIV stuff... If so, you need to add the CSS tag "display: inline;" to them, or "style='display:inline;'" Link to comment https://forums.phpfreaks.com/topic/126002-working-with-siblings-and-php-dom-question/#findComment-651596 Share on other sites More sharing options...
Demonic Posted September 26, 2008 Author Share Posted September 26, 2008 No, I'm loading a html file into the PHP DOM Document so I can grab certain stuff from the html sort of how I would using regular Javascript DOM. So far I can grab every H3 tag from the page like I want to, but I don't know how to get the sibling tags around it using PHP DOM. My question was, how do I grab the sibling tag and store the value in a variable. If so, you need to add the CSS tag "display: inline;" to them, or "style='display:inline;'" CSS and PHP don't have anything in common and they don't communicate what so ever. PHP Help forum, has nothing to do with CSS. What Is Dom Link to comment https://forums.phpfreaks.com/topic/126002-working-with-siblings-and-php-dom-question/#findComment-651598 Share on other sites More sharing options...
F1Fan Posted September 26, 2008 Share Posted September 26, 2008 Ya know, I'm sorry. I've had a long week and I misunderstood what you were asking. But I still try to help people on this site when I can. Comments like the ones you made make me wonder why I bother. Unless you're doing command-line PHP only, they do have something in common. PHP creates the HTML, CSS formats it. You don't wanna use CSS? Fine, what the hell do I care? Link to comment https://forums.phpfreaks.com/topic/126002-working-with-siblings-and-php-dom-question/#findComment-651604 Share on other sites More sharing options...
Demonic Posted September 26, 2008 Author Share Posted September 26, 2008 I understand, but I was just trying to make it clear for you and others what exactly I'm trying to accomplish. Link to comment https://forums.phpfreaks.com/topic/126002-working-with-siblings-and-php-dom-question/#findComment-651618 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.