【问题标题】:php - replace width , height src from rssphp - 从 rss 替换宽度、高度 src
【发布时间】: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-&gt;description);看$part_to_replace1 $part_to_replace2,你不能像这样把两个变量放在一起。您得到一个白页可能是因为您将 display_errors 设置为 false。把它放在你的 php 脚本的顶部:ini_set('display_errors', 1); error_reporting(-1);

标签: javascript php iframe preg-replace


【解决方案1】:

这是运行良好的代码!

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   
        }
        ?>

【讨论】:

    【解决方案2】:

    由于语法错误,您的脚本返回白屏。您不能以这种方式传递多个参数。

    这应该是它的宽度和高度:

    preg_replace('/width="[0-9]+" height="[0-9]+"/i', 'width="250" height="200"', $input_lines);
    

    【讨论】:

    • 你至少应该转义这些双引号。
    • @chris。哪个双引号必须转义?
    • 抱歉,刚刚解决了这个问题。 (复制和粘贴问题...)
    猜你喜欢
    • 2017-07-15
    • 2018-07-05
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    • 2011-03-17
    • 2016-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多