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

convert text file to json php

<?php
  header('Content-type: application/json');
  echo json_encode( explode("
",file_get_contents('data.txt')) );
?>
Comment

PREVIOUS NEXT
Code Example
Php :: required_if laravel 
Php :: laravel denny request by ip 
Php :: how to get week start date in php 
Php :: php unique id 
Php :: remove first 4 characters in string php 
Php :: destrroy a session php 
Php :: php add to existing associative array 
Php :: Laravel Code To Rename file on server in the storage folder 
Php :: carbon previous day 
Php :: check if phone number is valid php 
Php :: the uploaded file exceeds the upload_max_filesize in laravel 
Php :: laravel set session timeout 
Php :: laravel tree 
Php :: laravel artisan call with confirm 
Php :: pdo close connection 
Php :: take 10 skip 10 laravel 
Php :: php take picture with mobile camera 
Php :: laravel execute command from terminal 
Php :: phone number validation, laravel 
Php :: get numbers from string php 
Php :: string to decimal php 
Php :: model get last query in php 
Php :: laravel new line in language file 
Php :: round to 2 decimal places php 
Php :: how to change php variable value in javascript 
Php :: unlink(p1): No such file or directory 
Php :: laravel collection isempty 
Php :: laravel create request 
Php :: simplexml_load_string alternative php 
Php :: php object 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =