|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26644 file function works wrong
Submitted: 2003-12-17 05:50 UTC Modified: 2003-12-17 11:55 UTC
From: doris dot hahn at landover dot de Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 4.3.4 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
39 - 27 = ?
Subscribe to this entry?

 [2003-12-17 05:50 UTC] doris dot hahn at landover dot de
Hallo everybody,
I don't know if the problem I have is a bug or a feature in the new version.
I have a PHP skript which reads a text file into an array using the file function. This array than is worked up with an  array_walk. The text file contains SQL-statements which should be given to mysql_query. These statements contain apostrophes to mark character strings in SQL. 
In fewer PHP versions the statements are read as they are in the text file, in the new version back slashes are added to the apostrophes by the file function. So I get an error from mysql, naturally. 
Is this slash adding a new feature of the file function or is it a bug? If it is a new feature, which special characters are slash added too? The documentation says nothing about that. And there is no answer from the support side.
Thank you for your help.
Doris Hahn

Reproduce code:
  function sql_query_script ($zeile) {

    echo "$zeile<br>";

  }	// end function sql_query_script

//****  Main  *****************************************
	$filnam = "x.txt";
	$script = file ($filnam);
	array_walk ($script, "sql_query_script");

Expected result:
The text file x.txt contains the following line:
INSERT INTO Currency VALUES (0,'EUR',1000000)

I expect the script to output the following line:
INSERT INTO Currency VALUES (0,'EUR',1000000)

but the script outputs the following line:
INSERT INTO Currency VALUES (0,\'EUR\',1000000)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-17 11:20 UTC]
Do you have magic_quotes_runtime enabled?
 [2003-12-17 11:50 UTC] doris dot hahn at landover dot de
yes, magic_quotes_runtime is switched on
 [2003-12-17 11:55 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Turn them off and the problem will go away. When this ini setting is enabled any input processed by PHP (such as reading a file) will effectively go through addslashes().
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 10:01:30 2024 UTC