Search
 
SCRIPT & CODE EXAMPLE
 

PHP

write json file using php

Syntax:
file_put_contents(file_name.json.json_object);

$jsonData = {"poster":"film_poster.jpg","title":"fname","cost":"279.00","actors":[{"name":"Actor First Name","age":35,"city":"CityName"}]}

eg:
file_put_contents("geeks_data.json", $jsonData);
Comment

How to Write JSON to File in PHP

$data = array(
    'image' => $image_url,
    'mood' => $image_mood,
    'date' => $image_date
);

$data_array = file_get_contents($file_path);
$data_element = json_decode($data_array, true);
$data_element[] = $data;
$new_data = json_encode($data_element, JSON_PRETTY_PRINT);

if (!file_put_contents($file_path, $new_data)) {
    echo "success";
} else {
    echo "fail";
}
Comment

PREVIOUS NEXT
Code Example
Php :: laravel handle image validation 
Php :: change regards line laravel 
Php :: King Composer Theme Export 
Php :: LongestWord 
Php :: wp retrieve acf by category name 
Php :: add object to http request php behamin proxy bproxy 
Php :: costante php define 
Php :: how to prevent iframe for your site by PHP 
Php :: laravel belongsto with condition date 
Php :: Type error: Argument 1 passed to IlluminateDatabaseGrammar::parameterize() 
Php :: laravel get relation camelcase api 
Php :: Laravel database insert with combining array and string 
Php :: convert a value to a float in php 
Php :: php check bracket correct open and close 
Php :: laravel make model controller migration -mcr 
Php :: TypeError: Argument 1 passed to DrupalCoreEntityEntityViewBuilder::view() must implement interface 
Php :: model coomad laravel 
Php :: php html entity for url 
Php :: Php excel from Z to AA 
Php :: import csv file in laravel 8 
Php :: chunk in laravel 
Php :: PHP not echoing variables when print_r does 
Php :: how to generate unique alphanumeric 6 digit code through php myadmin 
Php :: get data in two columns in div in loop php 
Php :: Laravel Deployment to google cloud app engine flexible environment app.yaml file 
Php :: Dropzone Attachment Required is not working 
Php :: Argument 1 passed to IlluminateDatabaseGrammar::parameterize() 
Php :: vagrant no pg_hba.conf entry for host 
Php :: wordpress how to string multple function.php files together 
Php :: PHP Superglobal - $_REQUEST 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =