-1

I'm attempting to use PHP to get data from CallRail.com API via JSON.

However, I'm getting this error when previewing my PHP file directly in my browser: T_CONSTANT_ENCAPSED_STRING

My code:

<?
curl -H "Authorization: Token token={my-token-id}" \
-X GET \
"https://api.callrail.com/v2/a/{my-account-id}/calls.json"
?>

So far I have:

  • Read several articles related to the error without finding a solution or verifiably accurate explanation.
  • I've manually retyped all of the code to ensure I didn't have any improperly encoded characters or invalid white spaces.
  • I've also attempted to locate official documentation in the PHP docs but not found anything helpful.
  • And I've tested this in a blank PHP file so the code is completely isolated.

I don't know how to further debug this issue and am hoping someone can either identify the problem or share the steps to debug this on my own from this point.

Spencer Hill
  • 1,043
  • 2
  • 15
  • 38

1 Answers1

0

Your code sample is binary, to be executed from the command line in a shell like Bash, not PHP. This is why you're getting that error.

If you want PHP to call an external binary use exec(), shell_exec() or system().

Also, for portability, don't use the short open tags, ever, because it depends on the short_open_tag php.ini directive, or whether or not PHP was compiled with --enable-short-tags.

Even if your code doesn't have to be portable, it's just a bad habit. In case you ever need to work with some portable PHP code in the future; try:

<?php
echo shell_exec('curl -H "Authorization: Token token={my-token-id}" -X GET "https://api.callrail.com/v2/a/{my-account-id}/calls.json"');

Or if you want it on multiple lines, you could use implode:

<?php
echo shell_exec ( implode ( " ", [ 
        'curl',
        '-H "Authorization: Token token={my-token-id}"',
        '-X GET',
        '"https://api.callrail.com/v2/a/{my-account-id}/calls.json"' 
] ) );
Spencer Hill
  • 1,043
  • 2
  • 15
  • 38
hanshenrik
  • 19,904
  • 4
  • 43
  • 89
  • Okay, thanks. As I understand it, "binary" simply refers to any and all code. So don't you mean "bash"? Also, I don't know what short open tags are, or how it's relevant. Can you clarify in your Answer? – Spencer Hill May 07 '18 at 20:35