In this post i will describe to the users, how to load a JSON from the file in PHP. many a times coder need to access the json file as input data.
i am showing, how to load a json from a file and converted into the array or object in php.
if we read a json file as string then no need to converting into the array or object in php.
here i am using the file_get_contents function to achieve the target result.
$serverpath=$_SERVER['DOCUMENT_ROOT'];// server root directory
$filename="list.json"; // your json file path
$folder_name="yourfolder/"; // this is your folder name where your file is stored
$fullfile_path=$serverpath.$folder_name.$filename; // full file path for your json file d:\wamp\www\
$string = file_get_contents($fullfile_path); // read the file content and return as a string
$your_file_array = json_decode($string,true);// convert your json string to array with the json_decode function
/// print your json data/string as array