加载表时阻止关键字

时间:2014-10-14 03:44:24

标签: php

我调用下面的php文件,使用curl从表中加载数据,下面,我正在修剪它以防止显示超链接,我也在替换字符串以防止主机名检查(最后一部分)

<?php
        function curl($url){
            $headers[]  = "User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
            $headers[]  = "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            $headers[]  = "Accept-Language:en-us,en;q=0.5";
            $headers[]  = "Accept-Encoding:gzip,deflate";
            $headers[]  = "Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7";
            $headers[]  = "Keep-Alive:115";
            $headers[]  = "Connection:keep-alive";
            $headers[]  = "Cache-Control:max-age=0";    
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($curl, CURLOPT_ENCODING, "gzip");
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
            $data = curl_exec($curl);
            curl_close($curl);
            return $data;    
        }    
        $a = curl('http://www.domain.com/table');
        $regex = '#<a href=[^>]+>([^<]*)</a>#';    
        $b = preg_replace('#<a.*?>(.*?)</a>#i', '\1', $a);
        $c = str_replace('feed_container.innerHTML+=', 'aa=', $b);
        $d = str_replace("if(location.host.indexOf('hostnamekeyword')!=-1||location.host.indexOf('hostnamekeyword')!=-1)", "if (2==3)", $c);
        print $d;
    ?>

我现在要做的是以下内容: 如果有&#34; KEYWORD2&#34;在导入时连续,它忽略整行而不打印出来。 (不要显示)

即使代码只删除了KEYWORD2,它也可以完成这项工作。

以下是domain.com/table

的完整代码
function load_dse(){var feed_container=document.getElementById('filetoload');if(location.host.indexOf('hostnamekeyword')!=-1||location.host.indexOf('hostnamekeyword')!=-1){feed_container.innerHTML='<p>error</p>';}else{var head=document.getElementsByTagName('head')[0];var css=document.createElement('link');css.type='text/css';css.rel='stylesheet';css.href='http://www.domain.com/table';head.appendChild(css);var html='<table id=\"title\" border=\"0\"><tr><td class=\"first\">&nbsp;</td><th class=\"second\">title2</th><th class=\"third\">From / Time</th></tr><tr class=\"alt\"><td class=\"first\"><img src=\"http://domain.com/image1.gif\" /></td><td class=\"second\">somthing KEYWORD2 somthing else</td><td class=\"third\"><b>from</b>: e***i</td></tr><tr><td class=\"first\"><img src=\"http://domain.com/image2.gif\" /></td><td class=\"second\">somthing KEYWORD3 something else bla bla bla</td><td class=\"third\"><b>From</b>: r***o</td></tr><tr><td class=\"first\">&nbsp;</td><td class=\"second\"><b>title3</b>: <a href=\"http://domain.com\" rel=nofollow>maintitle</a></td><td class=\"third\">07-Oct-14 03:05</td></tr><tr class=\"alt\"><td class=\"first\"><img src=\"http://domain.com/image4.gif\" /></td><td class=\"second\">somthing3 bla bla bla KEYWORD4 bla bla somehting else bla</td><td class=\"third\"><b>From</b>: r***o</td></tr><tr class=\"alt\"><td class=\"first\">&nbsp;</td><td class=\"second\"><b>Item</b>: <a href=\"http://domain/com\" rel=nofollow>maintitle2</a></td><td class=\"third\">07-Oct-14 03:05</td></tr></table>';feed_container.innerHTML=html;feed_container.innerHTML+='<p><a href="http://www.domain.com/" style="display:inline;font-size:11px;color:#808080;text-decoration:none;font-family:Helvetica,Arial,sans-serif">title-new<span style="color:#4374b7">Another title</span></a></p>';}}
if(typeof window.addEventListener!="undefined")
window.addEventListener("load",filetoload,false);else if(typeof window.attachEvent!="undefined"){window.attachEvent("filetoload",lfiletoload);}
else{if(window.onload!=null){var oldOnload=window.onload;window.onload=function(e){oldOnload(e);window[filetoload]();};}
else
window.onload=filetoload;}

请帮助,我尝试了不同的方法,但无论我做什么,它都行不通。

2 个答案:

答案 0 :(得分:1)

检查这是否有用:

$e = preg_replace('#<tr.*?>.*KEYWORD2.*?<\/tr>#i', '', $d);
print $e;

这将删除包含KEYWORD2的表行 猜猜这就是你需要的。

您可以在此处查看结果:http://regex101.com/r/qQ2dE4/9
随着所有的解释和测试。非常好的网站!

答案 1 :(得分:0)

$e = preg_replace('#>* KEYWORD2#i', '', $d);
print $d;