【问题标题】:Use PHP to get embed src page information?使用PHP获取embed src页面信息?
【发布时间】:2011-11-05 04:34:10
【问题描述】:

有点奇怪的问题。

从 4shared 视频网站,我得到如下嵌入代码:

<embed src="http://www.4shared.com/embed/436595676/acfa8f75" width="420" height="320" allowfullscreen="true" allowscriptaccess="always"></embed>

现在,如果我访问该嵌入 src 中的 url,视频就会加载,并且页面的 URL 会更改为包含有关视频的信息。

我想知道是否有任何方法可以让我使用 PHP 访问该信息?我试过 file_get_contents 但它给了我很多奇怪的字符。

那么,我可以使用 PHP 加载嵌入 url 并获取地址栏中的信息吗?

感谢您的所有帮助! :)

【问题讨论】:

  • 您想要获取实际文件,还是http://www.4shared.com/embed/436595676/acfa8f75 的全屏版本,或者您所拥有的嵌入代码?很难理解。
  • 奇怪的字符可能是文件的二进制内容。

标签: php file url embed file-get-contents


【解决方案1】:

是的,例如使用curl-php 库。这将处理来自服务器的redirect-headers,从而产生视频的新/真实网址。

这是一个示例代码:

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.4shared.com/embed/436595676/acfa8f75");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);

// we want to further handle the content, so return it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// grab URL and pass it to the browser
$result = curl_exec($ch);

// did we get a good result?
if (!$result)
    die ("error getting url");

// if we got a redirection http-code, split the content in
// lines and search for the Location-header.
$location = null;
if ((int)(curl_getinfo($ch, CURLINFO_HTTP_CODE)/100) == 3) {
    $lines = explode("\n", $result);
    foreach ($lines as $line) {
        list($head, $value) = explode(":", $line, 2);
        if ($head == 'Location') {
            $location = trim($value);
            break;
        }
    }
}
if ($location == null)
    die("no redirect found in header");

// close cURL resource, and free up system resources
curl_close($ch);

// your location is now in here.
var_dump($location);
?>

【讨论】:

  • 我是 php 新手。你能给我一些代码吗?
  • 太棒了!就像我想要的那样工作。非常感谢! :D
猜你喜欢
  • 1970-01-01
  • 2011-07-12
  • 2017-11-16
  • 2017-10-02
  • 2013-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-05
相关资源
最近更新 更多