Created
December 14, 2018 14:06
-
-
Save sercanarga/f71bef9debf64e64def60bfb0c2c1755 to your computer and use it in GitHub Desktop.
PHP CURL Youtube Video Watch Count Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function video_count($v) { | |
$ch = curl_init(); | |
$v = 'https://www.youtube.com/watch?v='.$v; | |
curl_setopt($ch, CURLOPT_URL, $v); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$v = curl_exec($ch); | |
curl_close($ch); | |
preg_match_all('@<div class="watch-view-count">(.*?)</div>@si',$v, $c); | |
$c = implode($c[1]); | |
$c = explode(' ', $c); | |
return $c[0]; | |
} | |
echo video_count('u2kBNb79bN8'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment