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 :: php get last index end in foreach 
Php :: truncate table laravel eloquent 
Php :: how to take input in php 
Php :: object to string php 
Php :: delete file laravel 8 
Php :: Composer detected issues in your platform: Your Composer dependencies require a PHP version "= 8.0.2". 
Php :: path to php cli moodle in moodle 
Php :: laravel vue csrf 
Php :: change font family in echo php 
Php :: php string to char array 
Php :: php see if undefined 
Php :: limit offset array php 
Php :: wp display custom fields 
Php :: get user avatar wordpress 
Php :: upppercase php 
Php :: implode php 
Php :: how to print count query in php 
Php :: php search in object. array 
Php :: sentence get first second word php laravel 
Php :: Creating a Basic Route in Laravel 8 
Php :: include and require in php 
Php :: display all custom post type ids 
Php :: array_search 
Php :: array to string conversion in php 
Php :: laravel eloquent get last 
Php :: Laravel Auth Redirect based on role 
Php :: get woocommerce order details Object 
Php :: padding number in php 
Php :: $_GET["name"] 
Php :: taxonomy acf 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =