Skip to content

Instantly share code, notes, and snippets.

@sercanarga
Created December 14, 2018 14:06
Show Gist options
  • Save sercanarga/f71bef9debf64e64def60bfb0c2c1755 to your computer and use it in GitHub Desktop.
Save sercanarga/f71bef9debf64e64def60bfb0c2c1755 to your computer and use it in GitHub Desktop.
PHP CURL Youtube Video Watch Count Function
<?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