home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / HTML / AJAX / Serializer / Urlencoded.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  1.9 KB  |  68 lines

  1. <?php
  2. // $Id$
  3.  
  4. // {{{ http_build_query
  5. /**
  6.  * Replacement for http_build_query()
  7.  *
  8.  * @link   http://php.net/function.http-build-query
  9.  * @author vlad_mustafin@ukr.net
  10.  * @author Arpad Ray <arpad@php.net>
  11.  */
  12. if (!function_exists('http_build_query')) {
  13.     function http_build_query($formdata, $numeric_prefix = null, $key = null) 
  14.     {
  15.         $res = array();
  16.         foreach ((array)$formdata as $k => $v) {
  17.             if (is_resource($v)) {
  18.                 return null;
  19.             }
  20.             $tmp_key = urlencode(is_int($k) ? $numeric_prefix . $k : $k);
  21.             if (!is_null($key)) {
  22.                 $tmp_key = $key . '[' . $tmp_key . ']';
  23.             }
  24.             $res[] = (is_scalar($v))
  25.                 ? $tmp_key . '=' . urlencode($v)
  26.                 : http_build_query($v, null , $tmp_key);
  27.         }
  28.         $separator = ini_get('arg_separator.output');
  29.         if (strlen($separator) == 0) {
  30.             $separator = '&';
  31.         }
  32.         return implode($separator, $res);
  33.     }
  34. }
  35. // }}}
  36. // {{{ class HTML_AJAX_Serialize_Urlencoded
  37. /**
  38.  * URL Encoding Serializer
  39.  *
  40.  * @category   HTML
  41.  * @package    AJAX
  42.  * @author     Arpad Ray <arpad@php.net>
  43.  * @author     David Coallier <davidc@php.net>
  44.  * @copyright  2005 Arpad Ray
  45.  * @license    http://www.opensource.org/licenses/lgpl-license.php  LGPL
  46.  * @version    Release: 0.5.6
  47.  * @link       http://pear.php.net/package/HTML_AJAX
  48.  */
  49. class HTML_AJAX_Serializer_Urlencoded
  50. {
  51.     // {{{ serialize
  52.     function serialize($input) 
  53.     {
  54.         return http_build_query(array('_HTML_AJAX' => $input));
  55.     }
  56.     // }}}
  57.     // {{{ unserialize
  58.     function unserialize($input) 
  59.     {
  60.         parse_str($input, $ret);
  61.         return (isset($ret['_HTML_AJAX']) ? $ret['_HTML_AJAX'] : $ret);
  62.     }
  63.     // }}}
  64. }
  65. // }}}
  66. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  67. ?>
  68.