WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Forex Trading Online forex trading platform
Returns the JSON representation of a value

json_encode

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

json_encodeReturns the JSON representation of a value

Description

string json_encode ( mixed $value [, int $options ] )

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.

options

Bitmask constisting of PHP_JSON_HEX_QUOT, PHP_JSON_HEX_TAG, PHP_JSON_HEX_AMP, PHP_JSON_HEX_APOS. Defaults to 0.

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