Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php YouTube视图的Preg_匹配_Php_Youtube_Views_Preg Match - Fatal编程技术网

Php YouTube视图的Preg_匹配

Php YouTube视图的Preg_匹配,php,youtube,views,preg-match,Php,Youtube,Views,Preg Match,我是php新手,我面临着这个问题。需要一些帮助来匹配youtube的预匹配视图。 下面发布的代码是我为preg比赛制作的代码,但这些代码不起作用。有人能帮我吗。 if($row['type']=="Views"){ $data = $row['data']; $type = "YouTube Views"; //INSTAGRAM $file = @file_get_contents($data); preg_match('/\"watch-vie

我是php新手,我面临着这个问题。需要一些帮助来匹配youtube的预匹配视图。 下面发布的代码是我为preg比赛制作的代码,但这些代码不起作用。有人能帮我吗。

      if($row['type']=="Views"){
      $data = $row['data'];
      $type = "YouTube Views";
      //INSTAGRAM
$file = @file_get_contents($data);
preg_match('/\"watch-view-count":(.*?)\,/',$file,$mfc);  
$ccnt = $mfc[1];
//INSTAGRAM
      }
       if($row['type']=="Views"){
      $data = $row['data'];
       $type = "YouTube Views";
           //Views
$file = @file_get_contents($data) or die("YouTube Offline ? :/");
preg_match('/\"watch-view-count":(.*?)\,/',$file,$mfc);               
$ccnt = $mfc[1];
$data= 我需要preg_匹配来获取youtube视频中当前的浏览量。非常抱歉语法不好。

使用正则表达式解析HTML。改用a。这样会更有效率

      if($row['type']=="Views"){
      $data = $row['data'];
      $type = "YouTube Views";
      //INSTAGRAM
$file = @file_get_contents($data);
preg_match('/\"watch-view-count":(.*?)\,/',$file,$mfc);  
$ccnt = $mfc[1];
//INSTAGRAM
      }
       if($row['type']=="Views"){
      $data = $row['data'];
       $type = "YouTube Views";
           //Views
$file = @file_get_contents($data) or die("YouTube Offline ? :/");
preg_match('/\"watch-view-count":(.*?)\,/',$file,$mfc);               
$ccnt = $mfc[1];
在这种情况下,您可以简单地使用Youtube API:

<?php
$video_ID = 'BPmhFrwDJTo';
$JSON = file_get_contents("https://gdata.youtube.com/feeds/api/videos/{$video_ID}?v=2&alt=json");
$JSON_Data = json_decode($JSON);
$views = $JSON_Data->{'entry'}->{'yt$statistics'}->{'viewCount'};
echo $views.' views';
?>

对不起,伙计,我对php还不熟悉,但我还是尝试了这个。我不明白你到底想说什么???@Exception:我加了一个例子。希望有帮助!这对我很有帮助。谢谢你,伙计。