dqaq59269 2014-01-19 21:56
浏览 182

如何将编码的URL转换为PHP对象?

I have big form and had to serialize a part of it before sending to PHP to get rid of the limitation of "max_input_vars"

I want to convert the encoded value with PHP as orginal $_POST value.

I guess all i need to convert it to an object after decoded the post value but couldn't found the way.

Any help is really appreciated.

Best Regards

UPDATE: Here are the codes;

here is how I encode the form with javascript

    //searialize the form
    serialize_form = $(thisForm).serialize();
    serialize_form = "serialize_form="+encodeURIComponent(serialize_form);

Then in my php file;

    $formValues = urldecode( $_POST["serialize_form"] );

My php code was working fine before encode the serialized form, all need to have the same object with php after urldecode.

  • 写回答

1条回答 默认 最新

  • doulv1760 2014-01-19 22:23
    关注

    jQuery's serialize() returns something like this (taken from example on that page):

    single=Single2&multiple=Multiple3&check=check2&radio=radio2
    

    PHP has a function called parse_str that works like this:

    void parse_str ( string $str [, array &$arr ] )
    

    Usage example:

    $str = "first=value&arr[]=foo+bar&arr[]=baz";
    parse_str($str);
    echo $first;  // value
    echo $arr[0]; // foo bar
    echo $arr[1]; // baz
    
    parse_str($str, $output);
    echo $output['first'];  // value
    echo $output['arr'][0]; // foo bar
    echo $output['arr'][1]; // baz
    

    So call parse_str on your input and you can get either a list of variables or an array. I would do an array.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题