使用PHP获取嵌入src页面信息?

发布于 2024-12-02 05:55:58 字数 429 浏览 0 评论 0原文

有点奇怪的问题。

从 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 并获取地址栏中显示的信息吗?

感谢您的帮助! :)

Sort of a weird question.

From 4shared video site, I get the embed code like the following:

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

Now, if I access the url in that embed src, the video is loaded up and the URL of the page is changed with information about the video.

I am wondering if there is any way for me to access that info using PHP? I tried file_get_contents but it gives me lots of weird characters.

So, can I use PHP to load the embed url and get the information present in the address bar?

Thanks for all your help! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在深巷 2024-12-09 05:55:58

是的,例如使用 curl php 库。这个将处理来自服务器的重定向标头,这会产生新的/真实的视频的网址。

这是示例代码:

<?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);
?>

Yes, e.g. with the curl-library of php. This one will handle the redirect-headers from the server, which result in the new/real url of the video.

Here's a sample code:

<?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);
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文