Php YouTube视图的Preg_匹配
我是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
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:我加了一个例子。希望有帮助!这对我很有帮助。谢谢你,伙计。