0

I'm having an issue with JSON , my intention is to remove slash in starting

// [ { "id": "207437" ,"t" : "NIFTY" ,"e" : "NSE" ,"l" : "7,955.30" ,"l_fix" : "7955.30" ,"l_cur" : "Rs.7,955.30" ,"s": "0" ,"ltt":"9:46AM GMT 5:30" ,"lt" : "Oct 1, 9:46AM GMT 5:30" ,"lt_dts" : "2014-10-01T09:46:16Z" ,"c" : "-9.50" ,"c_fix" : "-9.50" ,"cp" : "-0.12" ,"cp_fix" : "-0.12" ,"ccol" : "chr" ,"pcls_fix" : "7964.8" }]

How i remove it

Matti Virkkunen
  • 63,558
  • 9
  • 127
  • 159
Angle
  • 5
  • 4

2 Answers2

0
$str = ltrim($str, '/ ');

That's it.. space is added as it looks that you have it there too.

ps: this is not a space there in the google's answer!! code below works.

$str = file_get_contents('http://finance.google.com/finance/info?client=ig&q=NSE:NIFTY,NSE:RELIANCE,NSE:SBIN,NSE:TCS,NSE:ONGC,NSE:HDFC,NSE:ITC%27');
$str = ltrim($str, chr(10).chr(47));
var_dump(json_decode($str)); 
Cheery
  • 16,063
  • 42
  • 57
  • @user3214110 ltrim cuts the listed symbols at the beginning of the string. In which way do you have your original data? – Cheery Oct 01 '14 at 04:25
  • my original code--- $url = 'http://finance.xyz.com/finance/info?client=ig&q=NSE:NIFTY,NSE:RELIANCE,NSE:SBIN,NSE:TCS,NSE:ONGC,NSE:HDFC,NSE:ITC'; $file = file_get_contents($url); – Angle Oct 01 '14 at 04:26
  • @user3214110 what do you mean by 'my original code'?? do you have it in the string or as an object? Are you sure you don't have other symbols there? – Cheery Oct 01 '14 at 04:28
0

use this code

$valid_json = substr($invalid_json, 2);

substr

(PHP 4, PHP 5) substr — Return part of a string

Description

string substr ( string $string , int $start [, int $length ] )
meda
  • 45,103
  • 14
  • 92
  • 122
  • Thanks Its Working i used it $valid_json = substr($invalid_json, 3); to remove starting slash... – Angle Oct 01 '14 at 04:46