Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

JSON PHP

A common use of JSON is to read data from a web server and display it on a web page.

This chapter will teach you how to exchange JSON data between the client and a PHP server.

The PHP File

PHP provides built-in functions to handle JSON.

Objects in PHP can be converted into JSON using the json_encode() function.

PHP file

<?php
$myObj->name = “John”;
$myObj->age = 30;
$myObj->city = “New York”;

$myJSON = json_encode($myObj);

echo $myJSON;
?>