php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24414 FREAD not function correctly on url reads
Submitted: 2003-06-30 11:43 UTC Modified: 2003-06-30 12:26 UTC
From: gfraley5 at earthlink dot net Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.2 OS: XP and Linux
Private report: No CVE-ID: None
 [2003-06-30 11:43 UTC] gfraley5 at earthlink dot net
Description:
------------
This code works perfectly on v4.3.1 and prior.  It no loner works on 4.3.2 nor on 4.3.3RC1.  I am using Apache 2.0.46.

<?
	$getNews = fopen("http://finance.yahoo.com/q?s=FON&d=t", "r");
	$readNews = fread($getNews, 32767);
	fclose($getNews);
	echo "<table><tr><td align=\"center\">";
	if (strpos($readNews,'New research reports for')!=FALSE) {
		list($FirstSplit1,$FirstSplit2)= split ("New research reports for", $readNews);
		list($SecondSplit1,$SecondSplit2)= split ("</a></font></td></tr></table>", $FirstSplit2);
		list($stockNews,$ThirdSplit2)= split ("<p><b><font face=arial size=-1>All headlines for:", $SecondSplit2);
	}
	$stockNews = str_replace("href=","target=\"_new\" href=",$stockNews);

	echo "<font size=\"1\"><b>Financial News For FON</b><br>$stockNews</font></td></tr></table></table>";
?>


Expected result:
----------------
Under 4.3.1 and prior:

Financial News For FON
Mon 6:15am FON Sprint, Sony, AOL in Mobile Content Distribution Pact - Dow Jones Business News 
Mon 6:01am FON Sprint and Warner Music Group Expand Relationship to Offer Customers America's First Full-Length Streamed Music Tracks in the Palm of Their Hands - PR Newswire 
Mon 6:01am FON Sprint Inks Deal With Clark County of Nevada for Sprint Ethernet Services(SM) - PR Newswire 
Mon 6:01am FON TriWest Healthcare Alliance Selects Sprint to Help Deliver Access To Healthcare Services for Military Personnel in 16 States - PR Newswire 
Mon 6:00am FON Sprint and Sony Music Entertainment Announce Broad Strategic Partnership To Distribute Mobile Entertainment Content - PR Newswire 
Mon 6:00am FON Hear It on Your Phone First: Sprint Launches the PCS Vision Music Channel, A One-Stop Source for Access to Wireless Music - PR Newswire 
Fri Jun 27 FON Sprint PCS Inks Streaming Music Deal With Sony, AOL -CNN - Dow Jones Business News 
Fri Jun 27 FON Sprint Employees Tackle Hunger for Harvesters - PR Newswire 
Thu Jun 26 FON Sprint Files To Sell 679,100 Earthlink Common Shares - Dow Jones Business News 
Thu Jun 26 FON KPMG sued by employee over tax shelter work - Reuters 
 


Actual result:
--------------
Under 4.3.2 and 4.3.3rc1

Financial News For FON


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-30 11:44 UTC] wez@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

4.3.0 and 4.3.1 were actually broken.
Please read the fread manual pages carefully.
http://www.php.net/manual/en/function.fread.php
 [2003-06-30 11:50 UTC] gfraley5 at earthlink dot net
Wez, I tried that but forgot to mention it.  Even with changing it to 'rb' it still does not work.
 [2003-06-30 12:20 UTC] wez@php.net
fread() is not guaranteed to return the number of bytes that you requested when working with anything other than local files.
You need to be prepared to read the data in chunks, as shown in the example towards the bottom of the manual page.

Even better, just use file_get_contents() to read the whole page.
 [2003-06-30 12:26 UTC] gfraley5 at earthlink dot net
Thank you.  file_get_contents works perfectly.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 01:01:28 2024 UTC