Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php return a json response

//PHP File
<?php
$data = /** whatever your data are **/;
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);

//In JS File
//JQUERY AJAX
        $.ajax({
        url: "path/to_php_file.php",
        dataType: "json",  
        type: "GET",
        data: {datax : datax },
Comment

how to receive json data in php

$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;
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

how to make a json request in php

<?php
$jsonurl = "http://api.wipmania.com/json";
$json = file_get_contents($jsonurl);
var_dump(json_decode($json));
?>
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 :: laravel blade @auth 
Php :: the uploaded file exceeds the upload_max_filesize directive in php.ini. wordpress 
Php :: php radians to degrees 
Php :: create laravel 8 resource route 
Php :: get redirect url for laravel socialite with api 
Php :: url segment laravel 
Php :: define php 
Php :: Undefined constant "STDOUT" in php 
Php :: autoloader php 
Php :: php difference between two dates in seconds 
Php :: acf get image id sub_field 
Php :: symfony messenger route 
Php :: string between two strings 
Php :: laravel passport client 
Php :: job execute async laravel 
Php :: how to use include in php 
Php :: get admin url wordpress 
Php :: php string to date 
Php :: How to display custom field in wordpress? 
Php :: how to assign variable in php 
Php :: display pdf file in laravel 
Php :: mp3 file upload code in php 
Php :: php interval day value 
Php :: file upload using ajax in laravel 
Php :: laravel add request 
Php :: how to run a php file in xampp 
Php :: laravel blade if else condition 
Php :: PHP join() Function 
Php :: PHP strrpos — Find the position of the last occurrence of a substring in a string 
Php :: laravel datatable render html 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =