fetch_description.php (747B)
1 <?php
2
3 /* Build URL to fetch the description from */
4 $url = "https://www.twitch.tv/" . $_GET["stream"];
5
6 /* Fetch HTML meta data (up until body starts) */
7 $handle = fopen($url, "r");
8 if ($handle) {
9 $html = stream_get_line($handle, 0, "<body>");
10 fclose($handle);
11 } else {
12 $html = "";
13 }
14
15 /* Fetch description line */
16 $desc_raw = preg_replace(
17 '/^.*(<meta[^>]+og:description[^>]+>).*/',
18 '\1',
19 $html
20 );
21
22 /* Ensure that double quotes are used consistently */
23 $desc_raw = preg_replace(
24 '/\'/',
25 '"',
26 $desc_raw
27 );
28
29 /* Extract description string */
30 $desc = preg_replace(
31 '/^.*content="([^"]+)".*$/',
32 '\1',
33 $desc_raw
34 );
35
36 /* return the html decoded description line */
37 echo htmlspecialchars_decode($desc);
38
39 ?>