title: Parse a json array in PHP to get the required values
body: <p>I am using a API provided by this website</p>
  
  <p><a href="http://pnrapi.alagu.net/" rel="nofollow">http://pnrapi.alagu.net/</a></p>
  
  <p>By using this API, we can get PNR status of our indian railways.</p>
  
  <p>I am using CURL to make a call and get the page content which is something like this, in an array format:</p>
  
  <pre>
  Array ( [url] => http://pnrapi.alagu.net/api/v1.0/pnr/4563869832 [content_type] => application/json;charset=utf-8 [http_code] => 200 [header_size] => 185 [request_size] => 130 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 2.906 [namelookup_time] => 0 [connect_time] => 0.312 [pretransfer_time] => 0.312 [size_upload] => 0 [size_download] => 548 [speed_download] => 188 [speed_upload] => 0 [download_content_length] => 548 [upload_content_length] => 0 [starttransfer_time] => 2.906 [redirect_time] => 0 [certinfo] => Array ( ) [primary_ip] => 50.57.204.234 [primary_port] => 80 [local_ip] => 192.168.1.10 [local_port] => 60105 [redirect_url] => [errno] => 0 [errmsg] => [content] => {"status":"OK","data":{"train_number":"16178","chart_prepared":false,"pnr_number":"4563869832","train_name":"ROCKFORT EXPRES","travel_date":{"timestamp":1369506600,"date":"26-5-2013"},"from":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20"},"to":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"alight":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"board":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20","timestamp":1369587000},"class":"2A","passenger":[{"seat_number":"W/L 39,RLGN","status":"W/L 27"}]}} )
  </pre>
  
  <p>but when I go to the URL <a href="http://pnrapi.alagu.net/api/v1.0/pnr/4563869832" rel="nofollow">http://pnrapi.alagu.net/api/v1.0/pnr/4563869832</a> , it gives me output as shown below:</p>
  
  <pre> {"status":"OK","data":{"train_number":"16178","chart_prepared":false,"pnr_number":"4563869832","train_name":"ROCKFORT EXPRES","travel_date":{"timestamp":1369506600,"date":"26-5-2013"},"from":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20"},"to":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"alight":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"board":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20","timestamp":1369587000},"class":"2A","passenger":[{"seat_number":"W/L  39,RLGN","status":"W/L  27"}]}}
  </pre>
  
  <p>Now, it seems that output on my web page with curl have got some extra text which is in the start as you can see both the outputs above.</p>
  
  <p>Well, my question is, how can I get the values from above array.  </p>
  
  <p>I am talking about the array output which I'm getting on my page using CURL, which looks like this:</p>
  
  <pre><code>Array ( 
  [url] =&gt; http://pnrapi.alagu.net/api/v1.0/pnr/4563869832 
  [content_type] =&gt;     application/json;charset=utf-8 
  [http_code] =&gt; 200 
  [header_size] =&gt; 185 
  [request_size] =&gt;     130 
  [filetime] =&gt; -1 
  [ssl_verify_result] =&gt; 0 
  [redirect_count] =&gt; 0 
  [total_time] =&gt; 2.906     
  [namelookup_time] =&gt; 0 
  [connect_time] =&gt; 0.312 
  [pretransfer_time] =&gt; 0.312 
  [size_upload] =&gt; 0 
  [size_download] =&gt; 548 
  [speed_download] =&gt; 188 
  [speed_upload] =&gt; 0 
  [download_content_length] =&gt; 548 
  [upload_content_length] =&gt; 0 
  [starttransfer_time] =&gt; 2.906 
  [redirect_time] =&gt; 0 
  [certinfo] =&gt; Array ( ) 
  [primary_ip] =&gt; 50.57.204.234 
  [primary_port] =&gt; 80 
  [local_ip] =&gt; 192.168.1.10 
  [local_port] =&gt; 60105 
  [redirect_url] =&gt; 
  [errno] =&gt; 0 
  [errmsg] =&gt; [content] =&gt; {"status":"OK","data":{"train_number":"16178","chart_prepared":false,"pnr_number":"4563869832","train_name":"ROCKFORT EXPRES","travel_date":{"timestamp":1369506600,"date":"26-5-2013"},"from":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20"},"to":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"alight":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"board":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20","timestamp":1369587000},"class":"2A","passenger":[{"seat_number":"W/L 39,RLGN","status":"W/L 27"}]}} )
  </code></pre>
  
  <p>Code in my PHP page is:</p>
  
  <pre><code>    &lt;?php
  function get_web_page( $url )
  {
  $options = array(
      CURLOPT_RETURNTRANSFER =&gt; true,     // return web page
      CURLOPT_HEADER         =&gt; false,    // don't return headers
      CURLOPT_FOLLOWLOCATION =&gt; true,     // follow redirects
      CURLOPT_ENCODING       =&gt; "",       // handle all encodings
      CURLOPT_USERAGENT      =&gt; "spider", // who am i
      CURLOPT_AUTOREFERER    =&gt; true,     // set referer on redirect
      CURLOPT_CONNECTTIMEOUT =&gt; 120,      // timeout on connect
      CURLOPT_TIMEOUT        =&gt; 120,      // timeout on response
      CURLOPT_MAXREDIRS      =&gt; 10,       // stop after 10 redirects
  );
  
  $ch      = curl_init( $url );
  curl_setopt_array( $ch, $options );
  $content = curl_exec( $ch );
  $err     = curl_errno( $ch );
  $errmsg  = curl_error( $ch );
  $header  = curl_getinfo( $ch );
  curl_close( $ch );
  
  $header['errno']   = $err;
  $header['errmsg']  = $errmsg;
  $header['content'] = $content;
  return $header;
  }
  $pnr = get_web_page('http://pnrapi.alagu.net/api/v1.0/pnr/4563869832');
  echo "&lt;code&gt;";
  print_r($pnr);
  echo "&lt;/code&gt;";
  ?&gt;
  </code></pre>
  
  <p>I only need the values under "content" which are train number, train name, travel date etc.</p>
  
  <p>So, what would be best way to extract this information into each variable?</p>
  
  <p>Like I want it like this:</p>
  
  <pre><code>$train_no   = [some code];
  $train_name = [some_code];
  </code></pre>
  
  <p>and so on...</p>
  
  <p>Thanks in advance.</p>
  
  <p>I tried this:</p>
  
  <p>echo $pnr['content'];</p>
  
  <p>and the output I got is:</p>
  
  <pre><code>{"status":"OK",    
  "data":"train_number":"16178",
  "chart_prepared":false,
  "pnr_number":"4563869832",
  "train_name":"ROCKFORT EXPRES",
  "travel_date":{"timestamp":1369506600,"date":"26-5-2013"},
  "from":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20"},
  "to":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},
  "alight":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},
  "board":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20","timestamp":1369587000},
  "class":"2A","passenger":[{"seat_number":"W/L 39,RLGN","status":"W/L 27"}]}}  
  </code></pre>
  
  <p>Now can any one give me an idea about how can I fetch unique values from above array?</p>