php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61152 parse_ini_string problem with html input
Submitted: 2012-02-21 07:39 UTC Modified: 2012-02-21 08:43 UTC
From: momchil dot bozhinov at hp dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.4.0RC8 OS: Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: momchil dot bozhinov at hp dot com
New email:
PHP Version: OS:

 

 [2012-02-21 07:39 UTC] momchil dot bozhinov at hp dot com
Description:
------------
I get a warning while trying to parse ini input.
problem is that the input comes from a file stored on the web and sometimes it 
comes back as HTML (proxy issue).
The warning is reported as "syntax error", which I understand as something that 
got out of the variable and was executed.

Test script:
---------------
<?php

$result = "<HTML><HEAD>
<TITLE>Network Error</TITLE>
</HEAD>
<BODY>
<FONT face=\"Helvetica\">
<big><strong></strong></big><BR>
</FONT>
<blockquote>
<TABLE border=0 cellPadding=1 width=\"80%\">
<TR><TD>
<FONT face=\"Helvetica\">
<big>Network Error (dns_unresolved_hostname)</big>
<BR>
<BR>
</FONT>
</TD></TR>
<TR><TD>
</FONT>
</TD></TR>
<TR><TD>
</BODY></HTML>";
	
parse_ini_string($result);

 // ===== 5.4 RC8	
// Warning: syntax error, unexpected '=' in Unknown on line 9
 // in C:\Users\***\Desktop\SFK\AutoPHP\bug.php on line 25
 
 // ===== 5.3.10
// Warning: syntax error, unexpected '=' in Unknown on line 9
 //in C:\Users\bozhinov\Desktop\SFK\AutoPHP\php53\bug.php on line 25
 
?>



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-21 07:48 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-02-21 07:48 UTC] rasmus@php.net
No, the ini parser is a parser much like PHP uses a parser to parse the language. 
Parsers generate syntax errors when the text they are trying to parse doesn't 
match the defined syntax. This is expected behaviour.
 [2012-02-21 08:00 UTC] momchil dot bozhinov at hp dot com
Thank you for explaining that. Sorry for rushing in and submitting a bug for it.
How would one validate INI input? It seems a bad idea to try and handle such 
warning as exception
 [2012-02-21 08:43 UTC] rasmus@php.net
Usually a syntax error in an ini file is a pretty serious situation that there 
is no recovery from. So a big warning tends to be warranted. But, if you really 
do have a situation where it is ok for there to be syntax errors in your ini, 
then just swallow the error and check the return.

eg.

if(!@parse_ini_string($result)) {
   echo "Fail!";
} else {
   echo "Ok";
}
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 07:01:31 2025 UTC