-1

I am using jQuery date range picker (http://tamble.github.io/jquery-ui-daterangepicker/) when I submit data its showing below format.

 {"start":"2015-09-17","end":"2015-09-23"}

Now, I want to pick date only like this

<?php
$startDate: 2015-09-17;
$endDate: 2015-09-23;
?>

I used php str_replace but its not work properly.

Your help would be very much appreciated.

John Conde
  • 217,595
  • 99
  • 455
  • 496
  • That's just json. Use [`json_decode()`](http://php.net/manual/en/function.json-decode.php) to to get an array or object back form which you can get those values. This is basic stuff. – John Conde Sep 23 '15 at 17:05

2 Answers2

1

To convert a JSON string to a PHP array, you can use json_decode(). Here's what your code might look like:

$jsonString = '{"start":"2015-09-17","end":"2015-09-23"}';
$array = json_decode($jsonString,true);

$startDate: $array['start'];
$endDate: $array['end'];

The second parameter of json_decode is true, which means the result will be an associative array (rather than an object).

Jake Bathman
  • 1,268
  • 3
  • 18
  • 25
0

this is the json format, use json_decode in php

Sjon
  • 4,989
  • 6
  • 28
  • 46
HEMANT SUMAN
  • 478
  • 2
  • 13