Ask a question about the parse_str function

Source: Internet
Author: User
Ask a question about the parse_str function. the parse_str function is very useful. you can convert a string to an array with an index. However, if the index value contains A. sign, it will automatically convert it to an underscore. For example:

$ Key = "modern educational technology ";

$ Postd [1] = "course. title = ";
$ Postdd = $ postd [1]. $ key;
Parse_str ($ postdd, $ fields );
Print_r ($ fields );

How can we prevent the parse_str function from converting the DOT to an underscore.


Reply to discussion (solution)

Parse_str works according to the HTTP protocol.
The. (dot) in the key name is replaced by _ (underline), which is an http protocol convention to prevent ambiguity.
If you want to convert them as they are, you have to write your own code.

$s = 'a.1=2&b.2=3';$p = '/&(?!amp;)/';foreach(preg_split($p, $s) as $v) {  $t = explode('=', $v);  $r[$t[0]] = $t[1];}print_r($r);
Array(    [a.1] => 2    [b.2] => 3)

Method1 = 1 & keyzy = name & keyword = Modern Educational Technology

The above string is parsed and becomes

Array ([method1] => 1)

Yes?

$ S = 'method1 = 1 & keyzy = name & keyword = '; $ p = '/&(?! Amp;)/'; foreach (preg_split ($ p, $ s) as $ v) {$ t = explode (' = ', $ v ); $ r [$ t [0] = $ t [1];} print_r ($ r );
Array ([method1] => 1 [keyzy] => name [keyword] => Modern Educational Technology)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.