Array keys encoded using http_build_query ()

Encoding a url array with http_build_query()

causes strange behavior when the array key is also html-char code.

For example:

return http_build_query([
   'id' = > ['my', 'data', 'here'], // no problem
   'class' = > ['my', 'data', 'here'], // no problem
   'yen' = > ['my', 'data', 'here'], // ¥ html car is ¥
   'parameter' = > ['my', 'data', 'here'], // ¶ html char is ¶
]);

      

and the encoded result:

id[0]=my&id[1]=data&id[2]=here&class[0]=my&class[1]=data&class[2]=here¥[0]=my¥[1]=data¥[2]=here¶meter[0]=my¶meter[1]=data¶meter[2]=here

What's going on here, it's possible, perhaps, that I can't use the word parameter as the array key.

+3


source to share


1 answer


If you look at the HTML output source you will see

id% 5B0% 5D = mine & id% 5B1% 5D = data & id% 5B2% 5D = here & class% 5B0% 5D = mine & class% 5B1% 5D = data & class% 5B2% 5D = here and amplifier; yen% 5B0% 5D = my & yen% 5B1% 5D = data & yen% 5B2% 5D = here & parameter% 5B0% 5D = mine & parameter% 5B1% 5D = data & parameter% 5B2% 5D = here

It is right. When rendered, only the browser interprets malformed objects such &yen

as ¥. There is nothing to worry about on the server side.



HTML reference objects

Demo: IDEOne

+1


source







All Articles