Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 替换iframe src的正则表达式-基于大小的preg_replace_Php_Regex_Iframe_Curl - Fatal编程技术网

Php 替换iframe src的正则表达式-基于大小的preg_replace

Php 替换iframe src的正则表达式-基于大小的preg_replace,php,regex,iframe,curl,Php,Regex,Iframe,Curl,我正在使用一个反向代理脚本,该脚本使用curl加载thepiratebay。它还有一个删除/替换广告的选项,但它使用stru_replace,我想知道是否有更好的方法 以下是当前脚本如何删除不需要的内容 <?php function remove_bloat($toremove){ include("configurationfile.php"); //Fix /static links so they work in subdirs $toremove = str_replace("s

我正在使用一个反向代理脚本,该脚本使用curl加载thepiratebay。它还有一个删除/替换广告的选项,但它使用stru_replace,我想知道是否有更好的方法

以下是当前脚本如何删除不需要的内容

<?php
function remove_bloat($toremove){
include("configurationfile.php");

//Fix /static links so they work in subdirs
$toremove = str_replace("src=\"/static","src=\"static" , $toremove);
$toremove = str_replace("href=\"/static","href=\"static" , $toremove);
$toremove = str_replace("url(\"/static","url(\"static" , $toremove);
$toremove = str_replace("url('/static","url('static" , $toremove);

$toremove = str_replace("//static.thepiratebay.se/","static/" , $toremove);

//Remove Ads

$toremove = str_replace('<iframe src="http://cdn1.adexprt.com/exo_na/center.html" width="728" height="90" frameborder="0" scrolling="no"></iframe>', $leaderboard, $toremove);
$toremove = str_replace('<iframe src="http://cdn2.adexprt.com/exo_na/center.html" width="728" height="90" frameborder="0" scrolling="no"></iframe>', $leaderboard, $toremove);

$toremove = str_replace('<iframe src="http://cdn1.adexprt.com/exo_na/sky2.html" width="160" height="600" frameborder="0" scrolling="no" style="padding-top: 100px"></iframe>', $rightside, $toremove);
$toremove = str_replace('<iframe src="http://cdn2.adexprt.com/exo_na/sky2.html" width="160" height="600" frameborder="0" scrolling="no" style="padding-top: 100px"></iframe>', $rightside, $toremove);

$toremove = str_replace('<iframe src="http://cdn1.adexprt.com/exo_na/sky1.html" width="120" height="600" frameborder="0" scrolling="no"></iframe>', $leftside, $toremove);
$toremove = str_replace('<iframe src="http://cdn2.adexprt.com/exo_na/sky1.html" width="120" height="600" frameborder="0" scrolling="no"></iframe>', $leftside, $toremove);

$toremove = str_replace('<iframe src="http://cdn1.adexprt.com/exo_na/bottom.html" width="728" height="90" frameborder="0" scrolling="no"></iframe>', $leaderboard, $toremove);
$toremove = str_replace('<iframe src="http://cdn2.adexprt.com/exo_na/bottom.html" width="728" height="90" frameborder="0" scrolling="no"></iframe>', $leaderboard, $toremove);

$toremove = str_replace('<iframe src="http://cdn1.adexprt.com/exo_na/top.html" width="468" height="60" frameborder="0" scrolling="no"></iframe>', $topsmall, $toremove);
$toremove = str_replace('<iframe src="http://cdn2.adexprt.com/exo_na/top.html" width="468" height="60" frameborder="0" scrolling="no"></iframe>', $topsmall, $toremove);

$toremove = str_replace('sessionHash', '', $toremove);
$toremove = str_replace('baypops.com', '', $toremove);

return $toremove;
}
怎么样:

$toremove = preg_replace('~<iframe src="http://cdn[0-9]+\.adexprt\.com[^"]+" width="469" height="60" frameborder="0" scrolling="no"></iframe>~', 'replaced content', $toremove);
$toremove=preg\u replace(“~怎么样:

$toremove = preg_replace('~<iframe src="http://cdn[0-9]+\.adexprt\.com[^"]+" width="469" height="60" frameborder="0" scrolling="no"></iframe>~', 'replaced content', $toremove);

$toremove=preg\u replace(“~如果广告是用cdn1而不是cdn2加载的呢?@Analog抱歉,我没有注意到这一点。现在呢?不幸的是,当我使用上面的代码时,它只是打断页面而没有显示任何错误消息。我想这可能是因为我出于某种原因使用了preg_replace,所以我尝试更改了一个原始的str_replace to preg_replace,同时将所有其他内容保留在同一行,以查看这是否也破坏了页面。但为了再次检查,我使用了下面的preg_replace,它确实有效,但它是一个更简单的正则表达式集,用于删除整个iframe,这不是我的意图$toremove=preg_replace('/','$toremove)@Analog噢,糟糕,我也忘了一些重要的东西。我会编辑我的答案。很好,最后的更改正是我所需要的。谢谢。如果广告是用cdn1而不是cdn2加载的,那该怎么办?@Analog抱歉,我没有发现这个区别。现在呢?不幸的是,当我使用上面的代码时,它只是在没有任何错误的情况下破坏了页面sages如图所示。我认为这可能是因为出于某种原因,我使用了preg_替换,所以我尝试将原来的str_替换之一更改为preg_替换,同时将所有其他内容保留在同一行,以查看这是否也破坏了页面。但为了再次检查,我使用了下面的preg_替换,它确实有效,但更简单regex设置删除整个iframe,这不是我的意图$toremove=preg_replace('/',''.$toremove);@Analog哦,糟糕,我也忘了一些重要的东西。我会编辑我的答案。很好,最后一次更改正是我所需要的。谢谢
 <iframe src="http://cdn2.adexprt.com/ividi/ividi.php?b=top&n=World_War_Z_%282013%29_UNRATED_1080p_BrRip_x264_-_YIFY" width="469" height="60" frameborder="0" scrolling="no"></iframe>
$toremove = preg_replace('<iframe src="/regular expression ?/" width="469" height="60" frameborder="0" scrolling="no"></iframe>', 'replaced content', $toremove);
$toremove = preg_replace('~<iframe src="http://cdn[0-9]+\.adexprt\.com[^"]+" width="469" height="60" frameborder="0" scrolling="no"></iframe>~', 'replaced content', $toremove);