【问题标题】:Why PhP samples at livecoin does not contains ?> bracket? [duplicate]为什么 livecoin 的 PhP 样本不包含 ?> 括号? [复制]
【发布时间】:2018-04-18 18:08:04
【问题描述】:

代码是https://www.livecoin.net/api/examples#vb

我尝试在 netbean 中添加右括号,但收到警告,提示不必要的右括号。我错过了什么?

<?php

$url = "https://api.livecoin.net/exchange/buylimit";
$apiKey = "gJx7Wa7qXkPtmTAaK3ADCtr6m5rCYYMy";
$secretKey = "8eLps29wsXszNyEhOl9w8dxsOsM2lTzg";

$params = array(
    'currencyPair'=> 'BTC/USD',
    'price'=> 60,
    'quantity'=>1
);

ksort($params);
$postFields = http_build_query($params, '', '&');
$signature = strtoupper(hash_hmac('sha256', $postFields, $secretKey));

$headers = array(
    "Api-Key: $apiKey",
    "Sign: $signature"
);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($statusCode!=200) {
    //dump info:
    echo "Status code: $statusCode, response: $response";
    //throw new Exception('Can not execute the query!');
}

var_dump(json_decode($response));

【问题讨论】:

  • 如果没有原始 HTML,通常不关闭 PHP 标记。其实it's in the Zend style guide not to do so.
  • PHP 关闭它自己的最后一个块。没必要。如果您想添加另一个块(php 或 html 等),这只是必要的

标签: php


【解决方案1】:

当您在该特定文件中只编写 PHP 代码时,不需要关闭 PHP ?&gt;,在这种情况下关闭 PHP 只是浪费性能。

【讨论】:

    猜你喜欢
    • 2012-07-29
    • 1970-01-01
    • 2014-08-20
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 2014-10-24
    • 2020-10-20
    • 2016-04-21
    相关资源
    最近更新 更多