|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55091 parse_ini_file: last escaped double-quote of multiline ends read
Submitted: 2011-06-30 14:51 UTC Modified: -
Avg. Score:2.5 ± 1.1
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: PinoyHarryPotter at gmail dot com Assigned:
Status: Open Package: Filesystem function related
PHP Version: 5.3.6 OS: Windows XP, CENTOS
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-06-30 14:51 UTC] PinoyHarryPotter at gmail dot com
When parsing an ini file with new lines and that the ini file requires double quotes to be escaped, PHP considers the last double-quote character in a line as the closing quote regardless if you escape the double-quote.

The story. I was trying to create an ini file to store the my Google AdSense. I was thinking that it might be a violation in their TOS if I try to remove the new lines, so I leave it at is.

At first, I tried escaping new lines with \n. But that does not work. It prints out the actual \n.

From the PHP documentation, there's a comment that it should be \\n. Which I did and prints out \n. So I did a research. Someone said to use \\\n which obviously does not work.

So I gave up trying so I use the actual line feed instead of using \n (I've read that this might be problematic especially if for instance, you code it in Windows and there's carriage return and then you ported it to Mac which gives out error when it finds it).

Now, the new line does work. Unfortunately, the moment it sees that the last character of the line is a double-quote, PHP reads it as an end even though it escapes with \"

See the result below. The last line ends as "<script type="text/javascript</div>"

I'm reporting this as a bug because it presents an unexpected outcome to an execution that should work differently (for the purpose it was created). I could, in fact, simply retain the original \n coding and do an str_replace for it.

Also, the example I gave is the way I use it. There are other ways new lines can be used with parse_ini_file. Its usage, for how it's going to be used, can become debatable that will eventually come down to "choice" (developer) and "control" (programmer).

Test script:
# PHP script
$var = parse_ini_file ('file.ini');
$var .= '</div>';
echo $var;

# ini file
google_ad = "<script type=\"text/javascript\"><!--
google_ad_client = \"xxx\";
google_ad_width = 728;\ngoogle_ad_height = 90;
<script type=\"text/javascript\"

Actual result:
<script type="text/javascript"><!--
google_ad_client = "xxx";
google_ad_width = 728;\ngoogle_ad_height = 90;
<script type="text/javascript</div>


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Jul 16 10:01:53 2018 UTC