billy2shoe Posted February 3, 2007 Share Posted February 3, 2007 hi there... I aim trying to do some code that basically reads a web-page and extracts certain information from it first: I am trying to write some code that reads a URL .. and prints the contest of the site out why doesnt this code work below???? I don't think the fopen("$URL", "r"); is working correctly ================================================= <? $URL = "http://www.dur.byethost4.com/screen_two/r_rules.php"; $file = fopen("$URL", "r"); $r = ""; do{ $data = fread($file, 8192); $r .= $data; echo "data: $data \n"; } while(strlen($data) != 0); ?> Quote Link to comment Share on other sites More sharing options...
fert Posted February 3, 2007 Share Posted February 3, 2007 $file=fopen($URL, "r"); Quote Link to comment Share on other sites More sharing options...
billy2shoe Posted February 3, 2007 Author Share Posted February 3, 2007 <? $URL = "http://www.dur.byethost4.com/screen_two/r_rules.php"; $file = fopen($URL, "r"); $r = ""; do{ $data = fread($file, 8192); $r .= $data; echo "data: $data $r\n"; } while(strlen($data) != 0); ?> Okay i have made this change..but why do i not get any out put from this logic above? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 3, 2007 Share Posted February 3, 2007 Instead of using fopen and fread to get the contents of a website, just use file_get_contents (http://www.php.net/file_get_contents), or file (http://www.php.net/file). Either of those will read the entire "text" (html) of the website into a variable (string in the case of the former, array for the latter). Quote Link to comment Share on other sites More sharing options...
billy2shoe Posted February 3, 2007 Author Share Posted February 3, 2007 hmmm interesting ... i read that site u sent me and use the code (example) ...and it doesnt work .. perhaps im doing something wrong .. the link is: http://au2.php.net/file (this is the code) <?php $lines = file('http://www.example.com/'); foreach ($lines as $line_num => $line) { echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.