从 imgur 嵌入

发布于 2024-12-05 19:29:01 字数 2070 浏览 0 评论 0原文

我目前正在使用此代码从 youtube 进行嵌入:

 if($e['domain'] == "youtube.com") {
            preg_match('/[\\?\\&]v=([^\\?\\&]+)/',$e['url'],$matches);
            if(count($matches) > 1) {
                $embed = true;
                $embed_code = "<object width='480' height='344'><param name='movie' value='http://www.youtube.com/v/" . $matches[1] . "?fs=1&amp;hl=en_US&amp;color1=FFFFFF&amp;color2=FFFFFF'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/" . $matches[1] . "?fs=1&amp;hl=en_US&amp;color1=FFFFFF&amp;color2=FFFFFF' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='480' height='344'></embed></object>";
            }
        }

并且我想对 imgur.com 使用相同的代码,它使用前缀“i”进行嵌入。所以图像是前缀+$e。我该如何让它发挥作用?

现在我已经尝试过:

    if($e['domain'] == "i.imgur.com") {
            preg_match('/[\\?\\&]([^\\?\\&]+)/',$e['url'],$matches);
            if(count($matches) > 1) {
                $embed = true;
                $embed_code = "<img src='http://i.imgur.com/' alt='' title='Hosted by imgur.com' />";
            }
        }

但我收到此错误消息: 注意:未定义变量:嵌入 /hsphere/local/home/xx/xx/xx/xx/view.php 第 107 行

编辑:以下是第 105-116 行:

            else $embed = false;

        if(isset($e['description']) || $embed == true) { ?>
            <tr class="listing_spacer_tr"><td colspan="6"></td></tr>
            <tr><td colspan="5"></td><td>
            <?php if($embed) echo $embed_code . "<br /><br />"; ?>

            <?php // DESCRIPTION
            if(isset($e['description'])) { ?>
            <div class="view_description"><?php echo make_clickable(nl2br($e['description'])); ?></div>
            <?php }
                } ?>

I'm currently using this code for embedding from youtube:

 if($e['domain'] == "youtube.com") {
            preg_match('/[\\?\\&]v=([^\\?\\&]+)/',$e['url'],$matches);
            if(count($matches) > 1) {
                $embed = true;
                $embed_code = "<object width='480' height='344'><param name='movie' value='http://www.youtube.com/v/" . $matches[1] . "?fs=1&hl=en_US&color1=FFFFFF&color2=FFFFFF'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/" . $matches[1] . "?fs=1&hl=en_US&color1=FFFFFF&color2=FFFFFF' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='480' height='344'></embed></object>";
            }
        }

And I want to use kind of the same for imgur.com which uses the prefix "i" for embedding. So the images are prefix+$e. How do I make it work?

Right now I've tried:

    if($e['domain'] == "i.imgur.com") {
            preg_match('/[\\?\\&]([^\\?\\&]+)/',$e['url'],$matches);
            if(count($matches) > 1) {
                $embed = true;
                $embed_code = "<img src='http://i.imgur.com/' alt='' title='Hosted by imgur.com' />";
            }
        }

But I get this error message:
Notice: Undefined variable: embed in /hsphere/local/home/xx/xx/xx/xx/view.php on line 107

EDIT: Here are the lines from 105-116:

            else $embed = false;

        if(isset($e['description']) || $embed == true) { ?>
            <tr class="listing_spacer_tr"><td colspan="6"></td></tr>
            <tr><td colspan="5"></td><td>
            <?php if($embed) echo $embed_code . "<br /><br />"; ?>

            <?php // DESCRIPTION
            if(isset($e['description'])) { ?>
            <div class="view_description"><?php echo make_clickable(nl2br($e['description'])); ?></div>
            <?php }
                } ?>

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

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

发布评论

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

评论(1

人│生佛魔见 2024-12-12 19:29:01

您发布的代码没有问题。您可能在其他地方遇到了一些问题。问题是读取,而不是为 $embed 变量赋值。

There isn't problem in code you have posted. You've probably got some problems somewhere else. Problem is reading, not assigning value to your $embed variable.

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