Advertisement
rodro1

Json data fectch from link on php

Oct 15th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. //way 1
  2.     $json = file_get_contents("https://jsonplaceholder.typicode.com/posts/1");
  3.     $obj = json_decode($json);
  4.     print_r($obj);
  5.  
  6. //way 2
  7.     $ch = curl_init();
  8.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  9.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  10.     curl_setopt($ch, CURLOPT_URL, 'https://jsonplaceholder.typicode.com/posts/1');
  11.     $result = curl_exec($ch);
  12.     curl_close($ch);
  13.  
  14.     $obj = json_decode($result);
  15.     print_r($obj);
  16.  
  17. //way 3 wordpress
  18.     $result = wp_remote_get( $url );
  19.  
  20.  
  21. //set data for 3 minute or any time session
  22. set_transient('jw_twitter_transient', $obj, 5*60);
  23. //or ur can set
  24. add_post_meta()
  25.  
  26. //get data
  27. get_transient( 'jw_twitter_transient' );
  28. //or u can get
  29. get_post_meta()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement