Nalin Nishant
Nalin Nishant

Reputation: 31

Editing with PHP give syntax error

I am trying to get only access token by removing all extra code but it always give me syntax error of ''

Here is my code

$top = $_GET["user"];

$line = '$top';
 $decoded = json_decode($line,true);

 $token2 = $decoded['access_token'];

$top

{"session_key":"5.uDUKhUqs4_N0Ow.1492573795.34-100007001746590","uid":100007001746590,"secret":"a01298dab24aa3c62adea05c6a79392e","access_token":"EAAAAAYsX7TsBAKXNrDxZB5Wx9vYY4HO8ux38JNIdTmYxwr15SFVuk0BOBeKQdS9C8BE4CzmIgxmghonZAjQmAl0E5pygW7s3eZCGEE4PxeXXO5kV5a2zt27LHo80YiekAZBzN3zHA9kuIiYNquvDLdgNaLlTtTObUZC1BrCKepc9NY7a3ieXaOSM0gsQePO9tf8nSykNahAZDZD","machine_id":"Y972WDldq3SeEw4bTWfnVj9Z","confirmed":true,"identifier":"9431448548"}

Upvotes: 2

Views: 50

Answers (1)

Sahil Gulati
Sahil Gulati

Reputation: 15141

Problem is here $line = '$top' Here you are using single quotes which defines the value of $line as $top instead of

{"session_key":"5.uDUKhUqs4_N0Ow.1492573795.34-100007001746590","uid":100007001746590,"secret":"a01298dab24aa3c62adea05c6a79392e","access_token":"EAAAAAYsX7TsBAKXNrDxZB5Wx9vYY4HO8ux38JNIdTmYxwr15SFVuk0BOBeKQdS9C8BE4CzmIgxmghonZAjQmAl0E5pygW7s3eZCGEE4PxeXXO5kV5a2zt27LHo80YiekAZBzN3zHA9kuIiYNquvDLdgNaLlTtTObUZC1BrCKepc9NY7a3ieXaOSM0gsQePO9tf8nSykNahAZDZD","machine_id":"Y972WDldq3SeEw4bTWfnVj9Z","confirmed":true,"identifier":"9431448548"}

Change this to:

$top = $_GET["user"];

$line = '$top';
$decoded = json_decode($line,true);

$token2 = $decoded['access_token'];

This:

$top = $_GET["user"];
$decoded = json_decode($top,true);
$token2 = $decoded['access_token'];

Upvotes: 3

Related Questions