Skip to content

Tiny PHP package to build HTTP URL query string compatible with Rails apps

License

Notifications You must be signed in to change notification settings

technically-php/rack-utils-http-query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RackUtils HTTP query

Tiny package to build HTTP URL query string compatible with Rails app.

Usage

This library produces output without explicit indices. As simple as that.

$vars = ['fruits' => ['apple', 'banana', 'orange']];
$query_string = \TechnicallyPhp\RackUtilsHttpQuery::build($vars);
var_dump($query_string); 
// will output: "fruits[]=apple&fruits[]=banana&fruits[]=orange"

Motivation

PHP stock http_build_query() converts array into items with indices explicitly defined. This is not compatible with the way Rails applications parse requests.

$vars = ['fruits' => ['apple', 'banana', 'orange']];
$query_string = http_build_query($vars);
var_dump($query_string); 
// will output: "fruits[0]=apple&fruits[1]=banana&fruits[2]=orange"

Relevant StackOverflow discussions:

  1. php url query nested array with no index

Details

This package follows Rack::Utils.parse_nested_query specification. Please check RackUtilsHttpQueryTest.php.

About

Tiny PHP package to build HTTP URL query string compatible with Rails apps

Resources

License

Stars

Watchers

Forks

Packages

No packages published