Php 从imgur嵌入
我目前正在使用以下代码从youtube嵌入:Php 从imgur嵌入,php,html,embed,Php,Html,Embed,我目前正在使用以下代码从youtube嵌入: if($e['domain'] == "youtube.com") { preg_match('/[\\?\\&]v=([^\\?\\&]+)/',$e['url'],$matches); if(count($matches) > 1) { $embed = true; $embed_code = "<obje
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' />";
}
}
但我得到了这个错误信息:
注意:未定义的变量:嵌入第107行的/hsphere/local/home/xx/xx/xx/view.php中
编辑:以下是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 }
} ?>
您发布的代码中没有问题。你可能在别的地方遇到了一些问题。问题是读取,而不是为$embed变量赋值 这是通知级别的警告。在声明$embed/为其分配某些内容之前,您正在尝试读取/访问$embed。在任何有意义的地方声明$embed,如果它不依赖于条件,则通知应消失。您没有在第107行提供代码,这是调用$embed变量的地方。否则$embed=false;如果设置$e['description']| |$embed==true{>-第105-107行编辑您的原始帖子并包括第100-110行,只要有来自youtube的链接,它就会完美地嵌入,但是当它来自imgur时,我会收到错误消息。这是第105-107行的代码:否则$embed=false;如果设置$e['description']|$embed==true{?>尝试更改刚刚发布到if-isset$embed和isset$e['description']以及$embed==true的if语句