dqxafj6830 2015-05-18 14:13
浏览 25

反向PHP。$ .param

There is a function in jQuery, $.param, that takes an object (can be a nested object too) and converts it to a string suitable for GET usage.

I was wondering if there is a PHP function that would take that string and convert it back to an array (or nested array, if that was the case). Is there such a function?

EDIT:

I'm sending this JS object (after $.param()-ing it):

{"categories": [90000]}

I'm reading it on the server side from $_GET and then I'm passing it to parse_str.

I also have a test code that recreates the expected PHP array.

The entire thing looks like:

$filter = $_GET["my_array"];
parse_str($filters, $_filters);
error_log(print_r($_filters, true), 4);
$x = [
    "categories" => [
        90000
    ]
];
error_log(print_r($x, true), 4);

The output of that code is:

(
    [categories] => Array
        (
            [0] => 90000
        ) 
)


(
    [categories] => Array
        (
            [0] => 90000
        ) 
)

So I assume they are identical. But then I'm passing that array to Yii's findAll method and it's working only with $x.

Maybe parse_str is mixing plain arrays and associative arrays when parsing and that is why findAll is not working?

  • 写回答

2条回答 默认 最新

  • doujing2497 2015-05-18 14:15
    关注

    I think you may be looking for parse_url or parse_str that Jon Stirling mentioned.

    Bear in mind that all the query parameters will already exist in the $_GET global.

    Usage for the query part of the URL.

    var_dump(parse_url($url, PHP_URL_QUERY));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)