-1

I have an Html file that in the future will be much larger, and another PHP document. In the PHP document, I will have the option of obtaining the number of subscribers and viewing my YouTube channel, and I want that information from the PHP file to reach the tag of the Html.

This is the PHP document:

<?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
?>

And this is the Html document:

    <!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>

So how can I send the subscriber information to the Span and the visualizations to the other span? Pliss help me to solve this.

1 Answers1

-1

Add echo statements to the 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: <?php echo $subscriber_count ?></span>
            </li>
            <li>
                <span>Views: <?php echo $view_count ?></span>
            </li>
        </ul>
</html>
</body>
</html>
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Please close under-researched duplicates. You are a role model to less experienced SO users -- please show them how to properly help this community. – mickmackusa Sep 07 '19 at 00:34
  • Nothing happens, it's as if the php was not linked to html. Only the span comes out without any information. – Frayni Calderón Sep 07 '19 at 00:41
  • @FrayniCalderón The HTML code has to be in the PHP file, not a separate file. – Barmar Sep 07 '19 at 00:45
  • You really need to read a tutorial on using PHP to produce web pages. – Barmar Sep 07 '19 at 00:46
  • So what do you recommend to put the number of subscribers and display in an html document? Because this is a test that I am doing. The HTML document of the page is almost 1000 line of code. And if I see that I can't use Php to make another programming language use with the YouTube API? – Frayni Calderón Sep 07 '19 at 00:54
  • Put the HTML in the PHP script. That's how you create dynamic web pages with PHP. – Barmar Sep 07 '19 at 00:56