• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 856
  • Last Modified:

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")?
0
kjenney
Asked:
kjenney
  • 2
  • 2
1 Solution
 
Kyle HamiltonData ScientistCommented:
...you could give this a whirl:

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


echo $title;
0
 
kjenneyAuthor Commented:
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

0
 
kjenneyAuthor Commented:
Great!
0
 
Kyle HamiltonData ScientistCommented:
Cheers- that's funny, I was about to post that same change :)

Glad you got it working!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now