尝试为每个数据点添加某种值,以便我可以将响应(仅数字)发送到现有表。我一直在网上搜索,没有CURL API响应似乎是这么简单,所以我可以找到一个答案。(对不起,新手,不懂"术语")
这是我能够在屏幕上显示的响应。
{"price": 2049.27, "change_point": -5.76, "change_percentage": -0.28, "total_vol"; "1.27 "}">
<html>
<?php
$url = 'https://realstonks.p.rapidapi.com/';
$collection_name = $_REQUEST["stock_name"];
$request_url = $url . '/' . $collection_name;
$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'X-RapidAPI-Host: www.xyz.com',
'X-RapidAPI-Key: xxxxxxxxxxxxxxxxxxx',
'Content-Type: application/json']);
$response = curl_exec($curl);
curl_close($curl);
//Uncomment bellow to show data on screen
echo $response . PHP_EOL;
enter code here
//var_dump(json_decode($json));
//var_dump(json_decode($json, true));
// Initiate curl
$ch = curl_init();
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
?>
我不太了解PHP,但这里到这里。如果我没弄错的话,我认为你想把$response
存储在<td>
元素中。此资源可以帮助https://www.daniweb.com/programming/web-development/threads/428730/how-to-display-php-variable-in-html