查看: 771|回复: 0

自动更新google的hosts轻松访问谷歌

[复制链接]
发表于 2016-6-17 10:45 | 显示全部楼层 |阅读模式
官方团队 2016-6-17 10:45 771 0 显示全部楼层

加个开机运行的任务计划,完美。。


<?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(‘&nbsp;’, ‘ ‘, $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);




您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 返回列表 发新帖

快速回复 返回顶部 返回列表