Getting content from external website by a div id

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sateesh
Forum Newbie
Posts: 2
Joined: Fri Jan 21, 2011 1:13 am

Getting content from external website by a div id

Post by sateesh »

Hi

I am developing a website on social engine. I have created a menu item for News and need to get the content for that menu item from an external website by a div id.

Here the problem is I am getting the content between the particular div id and as well as particular div class.
<div class="clearfix" id="ja-zinfp"> this is the source div.

<div class="something"> working good
<div id="something"> working good
<div class="clearfix" id="ja-zinfp"> not working

This is the line of code what I have wriiten for this task
preg_match_all ("/<div class=\"ja-content-top clearfix\">([^`]*?)<\/div>/", $data, $matches);
print_r($matches[1]);

Can anybody help me in this issue

Thanks
Sateeesh.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Getting content from external website by a div id

Post by josh »

sateesh
Forum Newbie
Posts: 2
Joined: Fri Jan 21, 2011 1:13 am

Re: Getting content from external website by a div id

Post by sateesh »

Actually I need to get the content from this div

preg_match_all ("/<div class=\"clearfix\" id=\"ja-zinfp\">([^`]*?)<\/div>/", $data, $matches);

Can I place the div as above

Thanks
Sateesh
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Getting content from external website by a div id

Post by John Cartwright »

XPath is basically a HTML query language.

Using Zend_Dom_Query, you could do something like

Code: Select all

$dom = new Zend_Dom_Query($html);
$results = $dom->query('#ja-zinfp');
Which will return a DOMElement for you to do with as you please :D
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Getting content from external website by a div id

Post by pickle »

This belongs in PHP-Code. Please make an attempt to post questions in the appropriate forum.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply