convert query String to json in php

前端 未结 3 613
孤独总比滥情好
孤独总比滥情好 2021-01-07 02:49

I send a QueryString formatted text like bellow to a php Script via Ajax:

title=hello&custLength=200&custWidth=300  

And I want to

3条回答
  •  生来不讨喜
    2021-01-07 03:16

    I realize this is old, but I've found the most concise and effective solution to be the following (assuming you can't just encode the $_GET global):

    parse_str('title=hello&custLength=200&custWidth=300', $parsed);
    
    echo json_encode($parsed);
    

    Should work for any PHP version >= 5.2.0 (when json_encode() was introduced).

提交回复
热议问题