从 imgur 嵌入
我目前正在使用此代码从 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>";
}
}
并且我想对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您发布的代码没有问题。您可能在其他地方遇到了一些问题。问题是读取,而不是为 $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.