Json & PHP support

Json ( JavaScript Object Notation) is the data interchange format used to transport data between pages, you can know more about Json here. Please note that PHP5.2 onwards Json support is built in and you can verify this by using your PHP info command.

We will learn some PHP commands on how to convert data array to Json string to transport the data across the pages.

Here it is how it will look within your php info on Json support.


If you are getting the above detail in your php info command then you can directly use the PHP Json functions without adding any additional class to your script.

Json with Ajax and JQuery

Json Ajax and Jquery
There are built in functions available in Jquery to handle Json data formats. This makes a good combination for building applications quickly with less coding.

Read more on how getJSON function is used in Jquery to read and display records

Let us start with the function to create a Json string by using arrays in PHP

Sample student JSON data

Sample JSON data

Example 2: Converting an Associative Array to JSON

Using json_encode(), we can easily convert an associative array into JSON format:

$data = array("name" => "John", "age" => 25, "city" => "New York");
$json_data = json_encode($data);
echo $json_data;
// Outputs: {"name":"John","age":25,"city":"New York"}

Example 3: Decoding JSON with an Object

We can decode JSON data into a PHP object:

$json = '{"name":"John","age":25,"city":"New York"}';
$obj = json_decode($json);
echo $obj->name; // Outputs: John

json_encode to generate Json string from PHP Array data
Json Data formatting to return database records to main script
Searching MySql database as we type using Ajax
Displaying all records based on selection of a drop down list box

PHP XML Ajax
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







sadik

10-02-2015

good




PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer