Javascript php-替换rss中的宽度、高度src
我已经替换了iframe的Javascript php-替换rss中的宽度、高度src,javascript,php,iframe,preg-replace,Javascript,Php,Iframe,Preg Replace,我已经替换了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( $pa
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
}
?>
我尝试的是替换iframe
的width
和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);
由于语法错误,脚本返回白色屏幕。您不能以这种方式传递多个参数 这应适用于宽度和高度:
preg_replace('/width="[0-9]+" height="[0-9]+"/i', 'width="250" height="200"', $input_lines);
下面是运行良好的代码
foreach ( $x->channel->item as $entry ){
$part_to_replace = array("http://metar.gr///www.youtube.com/");
$replaced = array("http://www.youtube.com/");
$entry->description = preg_replace( '/iframe width="[0-9]+" height="[0-9]+"/i ' , 'iframe width="100%" height="100%" ', $entry->description);
$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
}
?>
foreach($x->channel->item as$entry){
$part_to_replace=数组(“http://metar.gr///www.youtube.com/");
$replaced=数组(“http://www.youtube.com/");
$entry->description=preg_replace('/iframe width=“[0-9]+”height=“[0-9]+”/i',iframe width=“100%”height=“100%”,$entry->description);
$entry->description=str\u replace($part\u to\u replace,$replaced,$entry->description);
?>
这里有一个php语法错误:preg\u replace($part\u to\u replace1$part\u to\u replace2,$replaced1$replaced2,$entry->description)
看看$part_to_replace1$part_to_replace2
,你不能像这样把两个变量放在一起。你会得到一个白色的页面,可能是因为你的display_errors
设置为false。把它放在php脚本的顶部:ini_set('display_errors',1);错误报告(-1)
您至少应该转义这些双引号。@chris。所有双引号中哪一个必须转义?抱歉,刚刚修复了这个问题。(复制粘贴问题…)
foreach ( $x->channel->item as $entry ){
$part_to_replace = array("http://metar.gr///www.youtube.com/");
$replaced = array("http://www.youtube.com/");
$entry->description = preg_replace( '/iframe width="[0-9]+" height="[0-9]+"/i ' , 'iframe width="100%" height="100%" ', $entry->description);
$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
}
?>