Jump to content

simple html dom


kevin_007

Recommended Posts

suppose a page has the following tags

<div class = "news">
<div class = "article">
<h2>title 1</h2>
<div class = "content">
<p>content 1....</p>
</div>
</div>
<div class = "article">
<h2>title 2</h2>
<div class = "content">
<p>content 2....</p>
</div>
</div>
</div>

is it possible to check, using simple html dom library, whether the value of <h2> is title 1 and then if it is echo it, or store it in a variable?

what i've been able to do up to now is:

<?php

include('simple_html_dom.php');

foreach($article->find('div[class=news]') as $news)

{

foreach ($news->find('div[class=article]') as $content)

{

foreach ($content->find('h2') as $heading)

{

echo $heading;

 

}

}

}

?>

 

this only echos all the h2

Link to comment
https://forums.phpfreaks.com/topic/229891-simple-html-dom/
Share on other sites

I would personally suggest trying to do most of this using jQuery or simular. You could do:

 

$.(document).ready(function(){
    $.each("h2").html("Title 1", function(){
        $(this).html("Replaced Text");
    });
});

 

However, I'm not overly good with jQuery so you may want to edit that to make it work properly. :)

 

Hope this helps.

 

DarkMantis

Link to comment
https://forums.phpfreaks.com/topic/229891-simple-html-dom/#findComment-1184085
Share on other sites

I would personally suggest trying to do most of this using jQuery or simular. You could do:

 

$.(document).ready(function(){
    $.each("h2").html("Title 1", function(){
        $(this).html("Replaced Text");
    });
});

 

However, I'm not overly good with jQuery so you may want to edit that to make it work properly. :)

 

Hope this helps.

 

DarkMantis

 

I don't want to use Jquery because the page is an online page which i find it easier to work with simple html dom library and i don't know JQuery too much. Is it possible to check the value of h2 using simple html dom library?

Link to comment
https://forums.phpfreaks.com/topic/229891-simple-html-dom/#findComment-1185058
Share on other sites

  • 1 month later...

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.