0

I can't spot what's wrong with this php file. Can someone help. I've spent an hour looking at other solutions and I'm sure I've got the 's paired correctly

PHP 7.3.19-1~deb10u1 (cli) (built: Jul 5 2020 06:46:45) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.19, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.19-1~deb10u1, Copyright (c) 1999-2018, by Zend Technologies

Debian 10

#!/usr/bin/php
<?php
$ch = curl_init();
$header = array(
    'Content-type: application/vnd.api+json',
    'Accept: application/vnd.api+json',
 );
$postStr = json_encode(array(
    'grant_type' => 'client_credentials',
    'client_id' => 'client_id',
    'client_secret' => 'client_secret',
));
$url = 'https://example.com/Api/access_token';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$output = curl_exec($ch);
?>
  • 2
    The syntax looks correct. You probably have an invisible character messing things up. Try deleting the first 7 lines and retype them. – aynber Aug 05 '20 at 14:10
  • I tested and cannot replicate so I would go with what @aynber is saying here. – Jay Blanchard Aug 05 '20 at 14:11
  • Thanks for the suggestions. I checked it in Notepad++ for hidden / weird characters, I also checked out the article 'PHP parse/syntax errors; and how to solve them' but that didn't help. It won't parse the $header line , i removed this line and then it got stuck on $postStr line. @Jay did it run for you without errors? What version PHP/OS are you using? – Grey Chain Aug 06 '20 at 02:34
  • Found the problem , it was the encoding which as set to UTF8 not ANSI – Grey Chain Aug 06 '20 at 03:07

0 Answers0