开发者

Embed from imgur

开发者 https://www.devze.com 2023-04-06 17:53 出处:网络
I\'m currently using this code for embedding from youtube: if($e[\'domain\'] == \"youtube.com\") { preg_match(\'/[\\\\?\\\\&]v=([^\\\\?\\\\&]+)/\',$e[\'url\'],$matches);

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&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>";
            }
        }

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><开发者_StackOverflow中文版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 }
                } ?>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消