Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1376225
http_build_query.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Feb 1, 4:42 PM
Size
3 KB
Mime Type
text/x-php
Expires
Tue, Feb 3, 4:42 PM (6 h, 16 m)
Engine
blob
Format
Raw Data
Handle
884651
Attached To
rINP In-Portal
http_build_query.php
View Options
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Stephan Schmidt <schst@php.net> |
// | Aidan Lister <aidan@php.net>
// +----------------------------------------------------------------------+
//
// $Id: http_build_query.php,v 1.1 2004-10-26 18:22:16 kostja Exp $
//
/**
* Replace function http_build_query()
*
* @category PHP
* @package PHP_Compat
* @link http://php.net/function.http-build-query
* @author Stephan Schmidt <schst@php.net>
* @author Aidan Lister <aidan@php.net>
* @version $Revision: 1.1 $
* @since PHP 5
* @require PHP 4.0.1 (trigger_error)
*/
if
(!
function_exists
(
'http_build_query'
))
{
function
http_build_query
(
$formdata
,
$numeric_prefix
=
null
)
{
// If $formdata is an object, convert it to an array
if
(
is_object
(
$formdata
))
{
$formdata
=
get_object_vars
(
$formdata
);
}
// Check we have an array to work with
if
(!
is_array
(
$formdata
))
{
trigger_error
(
'http_build_query() Parameter 1 expected to be Array or Object. Incorrect value given.'
,
E_USER_WARNING
);
return
false
;
}
// If the array is empty, return null
if
(
empty
(
$formdata
))
{
return
null
;
}
// Start building the query
$tmp
=
array
();
foreach
(
$formdata
as
$key
=>
$val
)
{
if
(
is_integer
(
$key
)
&&
$numeric_prefix
!=
null
)
{
$key
=
$numeric_prefix
.
$key
;
}
if
(
is_scalar
(
$val
))
{
array_push
(
$tmp
,
urlencode
(
$key
).
'='
.
urlencode
(
$val
));
continue
;
}
// If the value is an array, recursively parse it
if
(
is_array
(
$val
))
{
array_push
(
$tmp
,
__http_build_query
(
$val
,
urlencode
(
$key
)));
continue
;
}
}
return
implode
(
'&'
,
$tmp
);
}
// Helper function
function
__http_build_query
(
$array
,
$name
)
{
$tmp
=
array
();
foreach
(
$array
as
$key
=>
$value
)
{
if
(
is_array
(
$value
))
{
array_push
(
$tmp
,
__http_build_query
(
$value
,
sprintf
(
'%s[%s]'
,
$name
,
$key
)));
}
elseif
(
is_scalar
(
$value
))
{
array_push
(
$tmp
,
sprintf
(
'%s[%s]=%s'
,
$name
,
urlencode
(
$key
),
urlencode
(
$value
)));
}
elseif
(
is_object
(
$value
))
{
array_push
(
$tmp
,
__http_build_query
(
get_object_vars
(
$value
),
sprintf
(
'%s[%s]'
,
$name
,
$key
)));
}
}
return
implode
(
'&'
,
$tmp
);
}
}
?>
Event Timeline
Log In to Comment