php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38323 Sections is not processed when parse_ini_file() which encoded in UTF-8 w/ BOM
Submitted: 2006-08-04 02:15 UTC Modified: 2006-10-18 21:26 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: zybersup at yahoo dot com Assigned: andrei (profile)
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.4.3 OS: Windows XP Professional
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: zybersup at yahoo dot com
New email:
PHP Version: OS:

 

 [2006-08-04 02:15 UTC] zybersup at yahoo dot com
Description:
------------
Call the function parse_ini_file() with INI file that written in UTF-8 with BOM.
Set process_sections to TRUE.
The result is an array of all value correctly parsed,
but no section processed.
(That means the result is not multi-dimentional array.)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-04 02:20 UTC] zybersup at yahoo dot com
Forgot to add more detail that...

I have tested files encoded in ASCII, UTF-8 w/ BOM and UTF-8 w/o BOM on both PHP4 and PHP5 (5.0.5)
Found no problem with ASCII and UTF-8 w/o BOM. Only UTF-8 w/ BOM has problem.
Also I found no problem with PHP 5.0.5. So that this problem should not caused by my INI file, I guess ;).
 [2006-08-04 07:55 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2006-08-04 17:24 UTC] zybersup at yahoo dot com
Script to reproduce the bug
============================

<?

$dir = dirname(__FILE__) . '/';
$ascii = parse_ini_file($dir . 'test_ascii.ini', true);
$utf8bom = parse_ini_file($dir . 'test_utf8bom.ini', true);
$utf8 = parse_ini_file($dir . 'test_utf8.ini', true);
print_r($ascii);
print_r($utf8bom);
print_r($utf8);

?>

Unsatisfied Result
===================
(Don't worry about the value, just check the difference of array structure)

Array
(
    [Section1] => Array
        (
            [Aval] => &#3607;&#3604;&#3626;&#3629;&#3610; &#3607;&#3604;&#3626;&#3629;&#3610; (Test Test)
            [Bval] => &#3652;&#3607;&#3618;
        )

    [Section2] => Array
        (
            [Cval] => Bar
            [Dval] => Foo
        )

)
Array
(
    [Aval] => &#3648;&#3608;?&#3648;&#3608;?&#3648;&#3608;&#3594;&#3648;&#3608;&#3597;&#3648;&#3608;&#65533; &#3648;&#3608;?&#3648;&#3608;?&#3648;&#3608;&#3594;&#3648;&#3608;&#3597;&#3648;&#3608;&#65533; (Test Test)
    [Bval] => &#3648;&#3609;&#65533;&#3648;&#3608;?&#3648;&#3608;&#3586;
    [Section2] => Array
        (
            [Cval] => Bar
            [Dval] => Foo
        )

)
Array
(
    [Section1] => Array
        (
            [Aval] => &#3648;&#3608;?&#3648;&#3608;?&#3648;&#3608;&#3594;&#3648;&#3608;&#3597;&#3648;&#3608;&#65533; &#3648;&#3608;?&#3648;&#3608;?&#3648;&#3608;&#3594;&#3648;&#3608;&#3597;&#3648;&#3608;&#65533; (Test Test)
            [Bval] => &#3648;&#3609;&#65533;&#3648;&#3608;?&#3648;&#3608;&#3586;
        )

    [Section2] => Array
        (
            [Cval] => Bar
            [Dval] => Foo
        )

)

Try testing a demo at http://www.theguru.co.th/zybersup/test_parse_ini.php
(May not keep there more than 2 months)
 [2006-08-04 19:49 UTC] andrei@php.net
Please provide access to the exact .ini file that is problematic. I could not reproduce this on PHP 4 or 5.
 [2006-08-05 06:29 UTC] zybersup at yahoo dot com
You can get the testing INI files from the same place of the testing script.

http://theguru.co.th/zybersup/test_utf8.ini
http://theguru.co.th/zybersup/test_utf8bom.ini
http://theguru.co.th/zybersup/test_utf8ascii.ini
 [2006-10-18 21:26 UTC] andrei@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

The reason this happens is because BOM is immediately adjacent to the "[Section 1]" portion. PHP 4 does not support Unicode. Thus, the parser cannot parse that line properly and treats the entries in that section as being global. You can either fix this by putting a newline before [Section 1] or upgrading to PHP 6.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 01:01:33 2024 UTC