Embed from imgur
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><开发者_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.
精彩评论