Link to home
Start Free TrialLog in
Avatar of potworny
potwornyFlag for Poland

asked on

PHP Simple HTML DOM Parser - select div with multiple classes

Hi,

I have a div:

<div class="mada rock rolling">Amateur question</div>

Open in new window


I want to find this div with the PHP Simple HTML DOM Parser.

The following code does not work:
$html->find('div.mada.rock.rolling');

Open in new window


Can you help me, brothers and sisters? :)
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Try:

$html->find('div[class=mada rock rolling]');

or try:

$html->find('div.mada .rock .rolling');
If above don't work:

$html->find('div[class=.mada.rock.rolling]');
Avatar of potworny

ASKER

brendonfeeley, I am looking at your answer :)

gr8gonzo, jkdt0077, this does not work:

$html->find("div[class='mada rock rolling']");
$html->find("div[class='mada .rock .rolling']")
$html->find('div[class=.mada.rock.rolling]');
$html->find('div.mada .rock .rolling');
This here seams quite simple:

simple html parser
What about these:

$html->find('div.mada, div.rock, div.rolling');

$html->find('div[class=mada], div[class=rock], div[class=rolling]');
Also, and forgive me if you know this, but:

$html->find('div.mada, div.rock, div.rolling');

Will return an array of matches. In order to output all matches, you will need to loop through them:

foreach($html->find('div.mada, div.rock, div.rolling') as $element) {
    echo $element->plaintext . '<br/>';
}
I don't think this lib can parse more than one class name...

I just load the HTML into a variable, replace the three classes with one name of my own and parse the modififed version of the HTML. :)
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
THANK you very much :)