php url query nested array with no index

前端 未结 4 1229
清歌不尽
清歌不尽 2021-01-11 15:28

I\'m working with a third party API that receives several parameters which must be encoded like this:

text[]=Hello%20World&text[]=How%20are%20you?&ht         


        
4条回答
  •  旧巷少年郎
    2021-01-11 16:16

    I don't know a standard way to do it (I think there is no such way), but here's an ugly solution:

    Since [] is encoded by http_build_query, you may generate string with indices and then replace them.

    preg_replace('/(%5B)\d+(%5D=)/i', '$1$2', http_build_query($params));
    

提交回复
热议问题