Link to home
Start Free TrialLog in
Avatar of kjenney
kjenney

asked on

QueryPath Extract from DIV class

I'm working with a simple example to try to understand how QueryPath (DOM) handles elements in a page. Here is the example:

<html>
<head><title>Test</title></head>
<body>
<div class="pup">
<img title="Test Title" src="myimage.jpg">
</div>
</body>
</html>

Open in new window


I've got this so far:

$testqp = htmlqp('test.html','body');
$header = $testqp->find('div[class="pup"]->img->title')->text();
echo $header;

Open in new window


How do I output the contents of the img/title (as seen above: "Test Title")?
ASKER CERTIFIED SOLUTION
Avatar of Kyle Hamilton
Kyle Hamilton
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
Avatar of kjenney
kjenney

ASKER

I was racking my brain trying to figure out why your solution didn't work. I played around with it and I got it to work. The Find method has to be closed and then chained to children. Thanks for the help!

$testqp = htmlqp('test.html','body');
$title = $testqp->find('div[class="pup"]')->children('img')->attr('title');
echo $title;

Open in new window

Avatar of kjenney

ASKER

Great!
Cheers- that's funny, I was about to post that same change :)

Glad you got it working!