【发布时间】:2014-06-03 20:00:18
【问题描述】:
我已经替换了 iframe 的 src 的一部分。
<?php
foreach ( $x->channel->item as $entry ){
$part_to_replace = array("http://123.gr///www.youtube.com/");
$replaced = array("http://www.youtube.com/");
$entry->description = str_replace( $part_to_replace, $replaced, $entry->description );
?>
<div data-role="collapsible" data-theme="b">
<h4><?php echo $entry->title; ?></h4>
<p><?php echo $entry->description; ?></p>
</div>
<?php
}
?>
这段代码运行良好!这是iframes 的示例,我是parsing
<iframe width="780" height="470" src="http://123.gr///www.youtube.com/embed/OZlyv68oNNM?rel=0&vq=hd720" frameborder="0" allowfullscreen></iframe>
我正在尝试替换width 的值和iframe 的height。
我绑定运行此代码,但结果是白屏。有什么想法吗?
$part_to_replace1= ' /width=".*?"/ /height=".*?"/ ';
$part_to_replace2 = array("http://123.gr///www.youtube.com/");
$replaced1= 'width="250" height="200"';
$replaced2 = array("http://www.youtube.com/");
$entry->description = preg_replace($part_to_replace1 $part_to_replace2 , $replaced1 $replaced2, $entry->description);
【问题讨论】:
-
你这里有一个php语法错误:
preg_replace($part_to_replace1 $part_to_replace2 , $replaced1 $replaced2, $entry->description);看$part_to_replace1 $part_to_replace2,你不能像这样把两个变量放在一起。您得到一个白页可能是因为您将display_errors设置为 false。把它放在你的 php 脚本的顶部:ini_set('display_errors', 1); error_reporting(-1);
标签: javascript php iframe preg-replace