tags:

views:

64

answers:

2

Hello I am using simple_html_dom to find every link in the html document that is of the class "new". Ordinarily I would use:

  $html->find('a[class=new]');

This would obtain links such as e.g.

<a class="new" ... blah blah ... />

Hoever the problem this time is that the html document contains links with classes such as

<a class="today new".../>
<a class="alksdjld new kfljslfd".../>

Basically lots of other links with the word new in it. The online manual says [class^=new] will partially solve this because it sorts for classes that START with new and that does work. but that still leaves classes like "new blah blah etc"

Hope that makes sense. Has anyone encountered this/solved this?

+1  A: 

Once you find the whole list of classes using [class^=new] can you loop through them and filter for the ones who only have a new as their only class ?

Zak
A: 

From the docs:

// Find all <li> in <ul>
foreach($html->find('ul') as $ul)
{
       foreach($ul->find('li') as $li)
       {
             // do something...
       }
}

So you should just be able to loop over your a records and look at $a->class to see if it == 'new' if not it will have more than just new in it and you can skip it...

Zak
I don't think what you say is possible. $html->find('a[class=new]'); foreach ($html as $value){ // }How do I then check the class == 'new' within the foreach statement? I don't think it works like that?
David Willis
sorry i meant $class = $html->find('a[class=new]'); foreach ($class as $value){ // } ..........Anyone?
David Willis
it would be more like if($value->class == "new") I think.
Zak
that syntax makes no sense
David Willis