How to attain the contents of a div from an external web pag

General discussions related to php

Moderators: macek, egami, gesf

karlmarsh05
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Dec 19, 2011 8:06 pm

How to attain the contents of a div from an external web pag

Postby karlmarsh05 » Fri Aug 17, 2012 5:55 am

Hi please help me :)

I am trying to basically echo the entire contents of a div located on an external file. The div contains text, images and links.

My existing method currently displays nothing when I execute the script. Why? Inspect element in google chrome also displays literally nothing!

<?php

$file = "http://myworld.ebay.co.uk/digitalzoneonline";

$data = file_get_contents($file);

preg_match_all ("/<div id=\"Content\">([^`]*?)<\/div>/", $data, $listings);

$content = $listings[1];
$total = count($content);
for($i=0; $i<$total; $i++){
echo $content[$i]."";
}

?>


Please please help.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: How to attain the contents of a div from an external web

Postby johnj » Wed Aug 22, 2012 9:07 pm

First, verify if the page is actually fetched. Check whether your $data has the page.

Then, start simple. try to use regular expression to match a simple <div> and then try the pattern that you want.


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 2 guests