2016-09-15 75 views
-1

我試着從其他網站獲取 視頻和海報讓我們把它叫做othersite.com如何使用的file_get_contents在PHP

其他site.com將視頻網址有這個參數:

<div class="player"> 
    <div id="l_player" class='l-player' > 
     <noscript> 
      <video style="width:100%; height:100%;" 
       controls="controls" 
       autobuffer="autobuffer" 
       class="player-html5" 
       preload="metadata" 
       poster="http://othersite.com/img.jpg"> 
       <source src="http://othersite.com/video.mp4" type="video/mp4"> 
      </video> 
     </noscript> 
    </div> 

與下面的PHP我從opengraph標籤的圖像,但是我試着讓MP4的網址,我不可能得到尚未

$Agent = array('http' => array('user_agent' => 'Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D)')); 
$String = file_get_contents('http://www.othersite.com/'. $video .'/', false, stream_context_create($Agent)); 
preg_match("/<source src=\"(.*)\" controls type=\"video\/mp4\"/", $String, $VideoURL); 
$VideoURL = $VideoURL[1]; 
$IMG = getstring($String,'<meta property="og:image" content="','"'); 

我的PHP越來越像只做你有什麼想法w ^帽子我在preg_match中做錯了以及如何獲得http://othersite.com/video.mp4

+1

源代碼中沒有'controls'。你也不應該使用正則表達式來解析HTML/XML。 – chris85

回答

1

這可以通過以下方式使用Preg_Match完成。這非常簡單,它工作得非常好!

$source = file_get_contents("That Page"); 

preg_match("'<source src=\"(.*?)\" type=\"video/mp4\">'si", $source, $match); 
if($match) echo "result=".$match[1]; 

這應該做你想做的。

經過最近的評論,我覺得我還應該補充說si修飾符使這個正則表達式更寬鬆。

+0

解決FluxCoder你是偉大的我的朋友,我從早上有這個,因爲它的準備將使這個解決thankyou verymuch.Do你有任何先進的鏈接學習這個邏輯? – Gazi

+0

答案應該有一個解釋。 'si'修飾符使得這個正則表達式更加鬆散。 – chris85

+0

不是真的,我希望能夠私下幫助你,但我實際上不知道你會怎麼做,沒有加入我的Skype:FluxCoder – FluxCoder

相關問題