Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php access json object

<?php
  // JSON string
  $someJSON = '[{"name":"Jonathan Suh","gender":"male"},{"name":"William Philbin","gender":"male"},{"name":"Allison McKinnery","gender":"female"}]';

  // Convert JSON string to Object
  $someObject = json_decode($someJSON);
  echo $someObject[0]->name; // Access Object data
?>
Comment

php return json data

header('Content-Type: application/json'); 

$colors = array("red","blue","green");
echo json_encode($colors);
Comment

access json object in php

$character = json_decode($data);
echo $character->name;
Comment

how to receive json data in php

$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;
Comment

access json with php

<?php

$data = '{
	"name": "Aragorn",
	"race": "Human"
}';

$character = json_decode($data);
echo $character->name;
Comment

json php

<?php
header("Content-Type: application/json; charset=utf-8");
if (!empty($_REQUEST['q'])){
    $q = $_REQUEST['q'];
    require_once('api-key.php');
    $apiUrl = "http://api.openweathermap.org/data/2.5/weather?q=" . $q . "&lang=fr&units=metric&APPID=" . API_KEY;
  
    $response = file_get_contents($apiUrl, False);
    $data = json_decode($response, true); // $data = TABLEAU PHP
  
    setLocale(LC_TIME,"fr_FR.UTF-8");
    date_default_timezone_set("Europe/Paris");
    $today = strftime('%A %d %B %y',time());
    $hour = date('H:i:s');
    // on prépare un tableau $json pour la réponse
    $json =  array("lieu" => $q,
                   "jour" => $today, 
                   "heure"=> $hour,
                   "meteo"=> array());
    $json['meteo']['main'] = $data['main'];
    $json['meteo']['description'] = $data['weather'][0]['description'];
    $json['meteo']['id'] = $data['weather'][0]['id'];
    echo json_encode($json,JSON_PRETTY_PRINT);
   }
Comment

return json in php

//code igniter
$query="qry";
$query = $this->db->query($query);
$res=$query->result();
return json_encode($res);
Comment

PHP code to read JSON string on server

$str_json = file_get_contents('php://input');
Comment

Returning JSON from a PHP Script

<?php
$data = /** whatever you're serializing **/;
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);
Comment

PREVIOUS NEXT
Code Example
Php :: php html to pdf 
Php :: replace word in string php 
Php :: php print object 
Php :: php add new item to associative array 
Php :: php detect crawler 
Php :: change default user table name laravel 
Php :: exception in php or try catch in php 
Php :: php class file upload 
Php :: Remove prefix on category title 
Php :: how to get the root domain in laravel 
Php :: get field object acf 
Php :: woocommerce return to shop custom url 
Php :: php slice array in half 
Php :: how to print on console with phpunit 
Php :: bagisto package generator 
Php :: php key value array to string 
Php :: How do you set a variable to an integer? in php 
Php :: call api php 
Php :: laravel invoice toturial 
Php :: material icons flutter list 
Php :: routes not defined 
Php :: php object is empty 
Php :: php integer 
Php :: apache use public folder as root 
Php :: laravel belongs to 
Php :: php include multiple files at once 
Php :: where like in laravel 
Php :: laravel get file to browser send 
Php :: determine if file is empty in php 
Php :: file get content php post 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =