首页 > 解决方案 > 从 php 中的站点获取部分 youtube 链接

问题描述

我需要一个获取//www.youtube.com/embed/AMUHafKH0oY?wmode=opaqueIDAMUHafKH0oY不断变化的 youtube 行,我需要它自动从该行中拉出...关闭此页面http://www.sequesteraccess.com/livefeed但它一直从页面上的第一个 youtube 视频中抓取,因此有关如何完成此操作的任何建议? 任何建议都会非常感谢提前!

这是我迄今为止尝试过的

<?php
    function getURL($u){
        $ops = array(
          'http'=>array(
            'method'=>"GET",
            'header'=>"Accept: text/html\r\n" .
                      "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0\r\n"
          )
        );
        $co = stream_context_create($ops);
        $r = file_get_contents('http://' . $u, false, $co);
        return $r != false ? $r : "";

    }
    function GetStringBetween($string, $start, $finish){
        $string = " ".$string;
        $position = strpos($string, $start);
        if ($position == 0) return "";
        $position += strlen($start);
        $length = strpos($string, $finish, $position) - $position;
        return substr($string, $position, $length);
    }
    $grab = file_get_contents('http://www.sequesteraccess.com/livefeed'); 
    $stream = GetStringBetween($grab, 'YOU ARE NEW TO SEQUE...&quot;&#125;,&quot;hSize&quot;:null,&quot;floatDir&quot;:null,&quot;html&quot;:&quot;&lt;iframe src=\&quot;//', '&amp');
?>
<?=$stream?>

标签: php

解决方案


推荐阅读