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:
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.
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"'
] ) );