我有一个Html文件,将来会更大,还有另一个PHP文档。在PHP文档中,我可以选择获取订阅者数量并查看我的YouTube频道,我希望PHP文件中的信息能够到达HTML的标签。
这是PHP文档:
<?php
// https://www.googleapis.com/youtube/v3/channels?part=statistics&id={Channel-ID}&key={Api-key}
$apiKey = 'APi-key';
//https://www.youtube.com/channel/{channel_id}
$channel_id = 'Channel-ID';
$response = file_get_contents('https://www.googleapis.com/youtube/v3/channels?part=statistics&id='. $channel_id .'&key='. $apiKey);
$data = json_decode($response);
$subscriber_count = $data->items[0]->statistics->subscriberCount;
$view_count = $data->items[0]->statistics->viewCount;
//This is the PHP document
?>
这是HTML文档:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<ul>
<li>
<span>Subscribers:</span>
</li>
<li>
<span>Views:</span>
</li>
</ul>
</html>
</body>
</html>
那么如何将订户信息发送到Span,将可视化内容发送到另一个Span?普利斯帮助我解决了这个问题。
答案 0 :(得分:-1)
在HTML中添加echo
语句。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<ul>
<li>
<span>Subscribers: <?php echo $subscriber_count ?></span>
</li>
<li>
<span>Views: <?php echo $view_count ?></span>
</li>
</ul>
</html>
</body>
</html>