Home >php教程 >php手册 >自动更新google的hosts

自动更新google的hosts

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 19:35:451518browse

加个开机运行的任务计划,完美。。 无 ?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);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn