[ Index ]

PHP Cross Reference of phool

title

Body

[close]

/Phool/Web/ -> JSON.php (summary)

(no description)

File Size: 741 lines (32 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Services_JSON:: (7 methods):
  __construct()
  utf162utf8()
  utf82utf16()
  encode()
  name_value()
  reduce_string()
  decode()


Class: Services_JSON  - X-Ref

Converts to and from JSON format.

Brief example of use:

<code>
// create a new instance of Services_JSON
$json = new \Phool\Web\Services_JSON();

// convert a complexe value to JSON notation, and send it to the browser
$value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
$output = $json->encode($value);

print($output);
// prints: ["foo","bar",[1,2,"baz"],[3,[4]]]

// accept incoming POST data, assumed to be in JSON notation
$input = file_get_contents('php://input', 1000000);
$value = $json->decode($input);
</code>
__construct($use = 0)   X-Ref

param: int     $use    object behavior flags; combine with boolean-OR

utf162utf8($utf16)   X-Ref
convert a string from one UTF-16 char to one UTF-8 char

Normally should be handled by mb_convert_encoding, but
provides a slower PHP-only method for installations
that lack the multibye string extension.

param: string  $utf16  UTF-16 character
return: string  UTF-8 character

utf82utf16($utf8)   X-Ref
convert a string from one UTF-8 char to one UTF-16 char

Normally should be handled by mb_convert_encoding, but
provides a slower PHP-only method for installations
that lack the multibye string extension.

param: string  $utf8   UTF-8 character
return: string  UTF-16 character

encode($var)   X-Ref
encodes an arbitrary variable into JSON format

param: mixed   $var    any number, boolean, string, array, or object to be encoded.
return: mixed   JSON string representation of input var

name_value($name, $value)   X-Ref
array-walking function for use in generating JSON-formatted name-value pairs

param: string  $name   name of key to use
param: mixed   $value  reference to an array element to be encoded
return: string  JSON-formatted name-value pair, like '"name":value'

reduce_string($str)   X-Ref
reduce a string by removing leading and trailing comments and whitespace

param: $str    string      string value to strip of comments and whitespace
return: string  string value stripped of comments and whitespace

decode($str)   X-Ref
decodes a JSON string into appropriate variable

param: string  $str    JSON-formatted string
return: mixed   number, boolean, string, array, or object



Generated: Thu Jun 4 19:17:11 2015 Cross-referenced by PHPXref 0.7.1