0

Hello everyone,
i had a question on how to pull certain content from a website using PHP and cURL and dislay it on a page? So far from the web, this is all i was able to find out, but this just saves the coding into a text document. Lets use php.net. Say i want to grab the information from the <div id="releaseBox"> which the latest release date on the right, and just diplay it. Like if it was 5.3.3 and i refreshed my paged, then it said 5.3.4 because they updated the release version. I really hope im making sense. Thanks for the help.

<?php

$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
?>

Edited by fobos: n/a

2
Contributors
5
Replies
9
Views
5 Years
Discussion Span
Last Post by cereal
0

Thanks for the help cereal. i was trying to echo the website into $f, then pull the div by id. 1, how do i get the web content into a variable.. like $f = geturlcontent? then call the div. 2, can i use $t = $dom->getElementById($f); to get the div that i want? basically what im trying to do is get stats of players from one website and post it on mine. this way ppl can come to my website and view stats of players and not have to visit the original website. i accidently posted in

http://www.daniweb.com/web-development/php/threads/376665

0

getElementById() works like in javascript, if the target page has <div id="mytest"></div> then write getElementById('mytest')
And the script can work if the page is well formed, if there is a doctype... an example:

<?php
$f = file_get_contents('http://website/');
$dom = new domDocument;
$dom->loadHTML($f);
echo $dom->getElementById('mytest')->nodeValue;
?>

Edited by cereal: n/a

0

So this is what i get..

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Unexpected end tag : p in Entity, line: 93 in F:\xampp\htdocs\Untitled-1.php on line 24

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: End tag : expected '>' in Entity, line: 163 in F:\xampp\htdocs\Untitled-1.php on line 24

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Unexpected end tag : scri in Entity, line: 163 in F:\xampp\htdocs\Untitled-1.php on line 24

Im guessing that its because that its not well written? Here is the code that you wrote

<?php
	$f = file_get_contents('http://combatarms.nexon.net/');
	$dom = new domDocument;
	$dom->loadHTML($f);
	echo $dom->getElementById('show')->nodeValue;
?>

The error is what i get above. I even tried this one..

<?php
$f = file_get_contents('http://combatarms.nexon.net/');

 $dom = new domDocument;
    $dom->loadHTML($f);
    $dom->preserveWhiteSpace = false;
    
    $t = $dom->getElementsByTagName('div'); // or getElementById('show')
    $newElement = $t->item(0)->nodeValue; // 0 to display #aaa, 1 for #bbb
    echo $newElement . "\n"
?>

I hope im not comming accros asking you to do this for me, but im stuck. youve been a help so far man. thx

0

Yes, it happens because the document is not written well.
Just add @ to load function: @$dom->loadHTML($f);

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.