php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55159 fopen encodes ampersand '&' as '&'
Submitted: 2011-07-07 16:32 UTC Modified: 2011-07-10 20:47 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: knappster_1 at hotmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.17 OS: Unix
Private report: No CVE-ID: None
 [2011-07-07 16:32 UTC] knappster_1 at hotmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.fopen%23Parameters
---
The function used to return a csv file with a stock quote with PHP 5.2.9.  However, now with 5.2.17 the function will replace '&' with '&' and it returns a csv file with just the text: "Missing Format Variable".

It is easy to verify by using a malformed URL with '&' in it and on the resulting html, view source and the error message will show '&' where '&' should be.  I have been unable to locate a workaround.  

Test script:
---------------
fopen("http://finance.yahoo.com/d/quotes.csv?s=ABT&f=sl1d1t1c1ohgvpnbaejkr&o=t", "r");


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-07 20:24 UTC] lonnyk at gmail dot com
I tested this on the 5.4 alpha and did not have this problem.

Here is my test script:
----------------------
<?php
error_reporting(E_ALL);
$fh = fopen("http://finance.yahoo.com/d/quotes.csv?
s=ABT&f=sl1d1t1c1ohgvpnbaejkr&o=t", "r");
while( !feof( $fh ) ){
        echo fgets( $fh ) . "\n";
}

Result:
---------------------

"ABT",53.54,"7/7/2011","4:01pm",+0.26,53.49,53.60,53.24,4932482,53.28,"Abbott 
Laboratori",N/A,N/A,2.87,44.59,54.24,18.56
 [2011-07-08 10:35 UTC] knappster_1 at hotmail dot com
-Status: Open +Status: Closed
 [2011-07-08 10:35 UTC] knappster_1 at hotmail dot com
I have tried your script on 2 Windows machines with Apache 2.2.11 and PHP 5.2.17 and my results match yours.  I was sure I saw it when I first upgraded to 5.2.17 on my machine, but this now seems to be an issue with the web host rather than a bug in php.  Sorry for the red herring.  I am changing the status to closed.
 [2011-07-10 20:47 UTC] cataphract@php.net
-Status: Closed +Status: Bogus
 [2011-07-10 20:47 UTC] cataphract@php.net
Closed is for fixed issues. Changing to Bogus.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 10 12:01:33 2025 UTC