Jump to content

Working with siblings and PHP DOM Question


Demonic

Recommended Posts

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?

 

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;'"

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.