php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42647 unexpected results from parse_str()
Submitted: 2007-09-12 18:27 UTC Modified: 2007-09-13 12:55 UTC
From: dev at glossword dot info Assigned:
Status: Not a bug Package: URL related
PHP Version: 5.2.4 OS: Windows XP
Private report: No CVE-ID: None
 [2007-09-12 18:27 UTC] dev at glossword dot info
Description:
------------
Hi. Before to make this post, I have read all previous bugs related to `parse_str()` and user comments in documentation for `parse_str()` function. Perhaps, this is not a bug but "consistent behavior"... Anyway, it didn't work as expected and it makes a trouble for me.

Reproduce code:
---------------
$str1 = '&arg1=123&arg2="Company&Sons" '90';
$str2 = '&arg1=123&arg2="Company&Sons" \'90';

parse_str($str1, $array1);
parse_str( html_entity_decode($str1), $array2 );
parse_str($str2, $array3);
parse_str( html_entity_decode($str2), $array4 );

print_r( $array1 );
print_r( $array2 );
print_r( $array3 );
print_r( $array4 );

Expected result:
----------------
Array
(
    [arg1] => 123
    [arg2] => "Company&Sons" '90
)
Array
(
    [arg1] => 123
    [arg2] => "Company&Sons" '90
)
...

Actual result:
--------------
Array
(
    [arg1] => 123
    [arg2] => 
    [quot;Company] => 
    [amp;Sons] => 
    [quot;_] => 
    [#039;90] => 
)
Array
(
    [arg1] => 123
    [arg2] => "Company
    [Sons"_] => 
    [#039;90] => 
)
Array
(
    [arg1] => 123
    [arg2] => "Company
    [Sons"_'90] => 
)
Array
(
    [arg1] => 123
    [arg2] => "Company
    [Sons"_'90] => 
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-12 18:40 UTC] dev at glossword dot info
Oh, as for $array3 and $array4 - it is correct. $array2 is partially correct.
 [2007-09-13 07:52 UTC] jani@php.net
My question is, how do you pass something like that via an URL?
(space is usually + IIRC.. :)
 [2007-09-13 07:54 UTC] jani@php.net
And & is %26..
 [2007-09-13 12:47 UTC] dev at glossword dot info
arg1 and arg2 are stings in HTML-code taken from database.
So, there is no condition when & could be %26 because & in HTML is &.

... a second later ...

I almost forgot to urlencode a few values. :-)
parse_url() works fine.
Bogus.
 [2007-09-13 12:55 UTC] iliaa@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

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 16:01:31 2024 UTC