php - How to cut off characters in JSON element -
i have following php code:
$curl = curl_init(); curl_setopt_array($curl, array( curlopt_url => "some_url", curlopt_returntransfer => true, curlopt_verbose => true, curlopt_encoding => "", curlopt_maxredirs => 10, curlopt_timeout => 30, curlopt_http_version => curl_http_version_1_1, curlopt_customrequest => "get", curlopt_httpheader => array( "cache-control: no-cache", "postman-token: 32bee9e5-7618-3b97-0239-f9f0185c7396" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); $response = json_decode($response, true); $reversed = array_reverse($response); foreach($reversed $json){ echo '<p>' . '<strong>' . $json['date'] . ' ' . $json["display_name"] . '</strong>' . '</p>' . '</ br>' . '<p>' . $json["description"] . '</p>'; } if ($err) { echo "curl error #:" . $err; } else { echo $response; } ?></code>
when echo reversed loop e.g. following output on date element: 2016-03-01 08:03:00.0
i remove last characters ":00.0".
i have tried many php functions, failing this.
use strtotime
, date
functions needed format:
// let's $json['date'] contains "2016-03-01 08:03:00.0" echo date("y-m-d h:i", strtotime($json['date'])); // output "2016-03-01 08:03"
Comments
Post a Comment