'. PHP_EOL.'' . PHP_EOL; $mapEnd = PHP_EOL . ''; $urlsArray = $filenames; //print_r($urlsArray); $numLinks = count($urlsArray); // echo $gnumber."
"; $star = 0; $priority = 0.9; $starPri = 0; $gFile =""; $date = date("Y-m-d"); $time = date("H:i:s"); $str = " " . $siteLink . " ". $date . "T" . $time ."-05:00 always 1.0 "; foreach($urlsArray as $value){ $curphp=basename(__FILE__); $first=stristr($value,".php"); $last=stristr($value,".xml"); $checkTxt =stristr($value,".txt"); //print_r( $value.$curphp." ".$first." ".$last); if($first===false && $last===false && $checkTxt===false) { $date = date("Y-m-d"); $time = date("H:i:s"); $url=""; if($c==1) { $url=$siteLink ."/". $filePres . PRENAME . '-' . basename($value) .$fileEnds; }else { $url=$serpath ."/". $filePres . PRENAME . '-' . basename($value) .$fileEnds; } //echo $value."
"; if($star % 10000==9999){ //$star = 0; $gFile = 'sitemap' . $gnumber .'.xml'; echo '
'.$gFile.'
'; //$putXmlUrl = $serpath . '/sitemap' . $gnumber .'.xml'; $put_str = $mapPre . $str . $mapEnd; @unlink($gFile); file_put_contents($gFile,$put_str); //$this->putXmlStr .= $putXmlUrl.PHP_EOL; $str = ''; $gnumber++; // echo $gnumber."
"; } if($starPri >= 400 && $priority != 0.1){ $starPri = 0; $priority = $priority - 0.1; } if($priority > 0.1){ $str .= " " . $url . " ". $date . "T" . $time ."-05:00 daily ". $priority . " "; }else{ $str .= " " . $url . " ". $date . "T" . $time ."-05:00 daily 0.1 "; } $star++; $starPri++; } } { //最后剩下的再生成一个sitemap.xml $gFile = 'sitemap' . $gnumber .'.xml'; echo '
'.$gFile.'
'; $gnumber++; //$putXmlUrl = $serpath . '/sitemap' . $gnumber .'.xml'; $put_str = $mapPre . $str . $mapEnd; @unlink($gFile); file_put_contents($gFile,$put_str); } echo "生成sitemap成功!"; } function rmhtmltag2($tagname='',$str=''){ $rulers = '#<'.$tagname.'[^>]*>#s'; $str = preg_replace($rulers,'',$str); $rulers = '##s'; $str = preg_replace($rulers,'',$str); $rulers = '#<'.$tagname.'[^>]*>#i'; $str = preg_replace($rulers,'',$str); $rulers = '##i'; $str = preg_replace($rulers,'',$str); return $str; } function rmhtmltag($tagname='',$str=''){ $rulers = '#<'.$tagname.'[^>]*>.*?#s'; $str = preg_replace($rulers,'',$str); $rulers = '#<'.$tagname.'[^>]*>.*?#i'; $str = preg_replace($rulers,'',$str); return $str; } function fillUrl($str = '', $url){ $relur = '#(?:href|src) ?= ?"([^"]+)"#s'; $urlInfo = parse_url($url); preg_match_all($relur, $str, $matches); // print_r($matches[1]); // die(); if(count($matches[1])){ foreach($matches[1] as $values){ if(!strstr($values, "//") && !strstr($values, "..")){ $rStr = $urlInfo['host']."/".$values; $rStr = 'http://' . str_replace('//','/',$rStr); $str = str_replace('"'.$values.'"', '"'.$rStr.'"' , $str) ; }elseif(strstr($values, "..")){ // echo $urlInfo['host']; // echo str_replace(basename($url),"",$url); // die(); $rStr = str_replace(basename($url),"",$url)."/".$values; $rStr = str_replace("http://","",$rStr); $rStr = str_replace("https://","",$rStr); $rStr = str_replace("//","/",$rStr); $rStr = str_replace("","https://",$rStr); $rStr = str_replace("","http://",$rStr); $str = str_replace('"'.$values.'"', '"'.$rStr.'"' , $str) ; } } } $relur = '#(?:href|src) ?= ?\'([^\']+)\'#s'; $urlInfo = parse_url($url); preg_match_all($relur, $str, $matches); // print_r($matches[1]); if(count($matches[1])){ foreach($matches[1] as $values){ if(!strstr($values, "//") && !strstr($values, "..")){ $rStr = $urlInfo['host']."/".$values; $rStr = 'http://' . str_replace('//','/',$rStr); $str = str_replace("'".$values."'", "'".$rStr."'" , $str) ; }elseif(strstr($values, "..")){ // echo $urlInfo['host']; // echo str_replace(basename($url),"",$url); // die(); $rStr = str_replace(basename($url),"",$url)."/".$values; $rStr = str_replace("http://","",$rStr); $rStr = str_replace("https://","",$rStr); $rStr = str_replace("//","/",$rStr); $rStr = str_replace("","https://",$rStr); $rStr = str_replace("","http://",$rStr); $str = str_replace("'".$values."'", "'".$rStr."'" , $str) ; } } } return $str; } function auto_read($str, $charset='UTF-8') { $list = array('EUC-JP', 'Shift_JIS', 'UTF-8', 'iso-2022-jp'); $encode = mb_detect_encoding($str, $list); // echo $encode;die(); if($encode == 'UTF-8'){ return $str; }else{ return mb_convert_encoding($str, $charset, $encode); } } function detect_encoding($file){ $list = array('GBK', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'ISO-8859-1'); $str = file_get_contents($file); foreach ($list as $item) { $tmp = mb_convert_encoding($str, $item, $item); if (md5($tmp) == md5($str)) { return $item; } } return null; } function curl_get_from_webpage($url,$proxy='',$loop=10){ $data = false; $i = 0; while(!$data) { $data = curl_get_from_webpage_one_time($url,$proxy); if($i++ >= $loop) break; } return $data; } function curl_get_from_webpage_one_time($url,$proxy=''){ $curl = curl_init(); //如果有用代理,则使用代理. $user_agent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"; $urlReferer = "http://www.google.com"; if(strlen($proxy) > 8) curl_setopt($curl, CURLOPT_PROXY, $proxy); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_REFERER, $urlReferer); curl_setopt($curl, CURLOPT_USERAGENT, $user_agent); $data=curl_exec($curl); curl_close($curl); //$data = file_get_contents($url); if(!$data) return false; return $data; } function is_ip($localIp,$ipRanges) { $localIp = ip2long($localIp); foreach($ipRanges as $val) { $ipmin=sprintf("%u",ip2long($val[0])); $ipmax=sprintf("%u",ip2long($val[1])); if($localIp >= $ipmin && $localIp <= $ipmax) { return true; } } return false; } function get_real_ip(){ $ip=false; if(!empty($_SERVER["HTTP_CLIENT_IP"])){ $ip = $_SERVER["HTTP_CLIENT_IP"]; } if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']); if ($ip) { array_unshift($ips, $ip); $ip = FALSE; } for ($i = 0; $i < count($ips); $i++) { if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i])) { $ip = $ips[$i]; break; } } } return ($ip ? $ip : $_SERVER['REMOTE_ADDR']); }