downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  

<JSON FunctionsMisc.>
Last updated: Thu, 26 Jun 2008

json_encode

(PHP 5 >= 5.2.0, PECL json:1.2.0-1.2.1)

json_encode — Returns the JSON representation of a value

Description

string json_encode ( mixed $value )

Returns a string containing the JSON representation of value .

Parameters

value

The value being encoded. Can be any type except a resource.

This function only works with UTF-8 encoded data.

Return Values

Returns a JSON encoded string on success.

ChangeLog

Version Description
5.2.1 Added support to JSON encode basic types

Examples

Example #1 A json_encode() example

<?php
$arr
= array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);

echo
json_encode($arr);
?>

The above example will output:

{"a":1,"b":2,"c":3,"d":4,"e":5}

See Also



add a noteadd a note User Contributed Notes
Returns the JSON representation of a value
There are no user contributed notes for this page.




<JSON FunctionsMisc.>
Last updated: Thu, 26 Jun 2008
show source | credits | sitemap | contact | advertising | mirror sites
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://phpbuilder.com/
Last updated: Tue Nov 1 20:20:59 2005 EST
Columns / Articles | Tips / Quickies | News | News Linking and RSS Feeds | Shared Code Library
Mail Archives | Support / Discussion Forums | Get Started! Links | Contribute! | Docs