加个开机运行的任务计划,完美。。 无 ?php$hostsFile = "C:/Windows/System32/drivers/etc/hosts";$RegExp = '/#google hosts [0-9]+ by 360kb.com[\s\S]+#google hosts [0-9]+ end/';$html = strip_tags(file_get_contents('http://www.360kb.com/kb/2_122.
加个开机运行的任务计划,完美。。
<?php $hostsFile = "C:/Windows/System32/drivers/etc/hosts"; $RegExp = '/#google hosts [0-9]+ by 360kb.com[\s\S]+#google hosts [0-9]+ end/'; $html = strip_tags(file_get_contents('http://www.360kb.com/kb/2_122.html')); preg_match($RegExp, $html, $matchs); $googleHosts = str_replace(' ', ' ', $matchs[0]); //echo $googleHosts; $hosts = file_get_contents($hostsFile); if(preg_match($RegExp, $hosts)){ $hosts = preg_replace($RegExp, $googleHosts, $hosts); }else{ $hosts .= "\r\n\r\n".$googleHosts."\r\n\r\n"; } file_put_contents($hostsFile, $hosts);