php產生 google map代碼
<title>Google Sitemap產生器</title>
<style type="text/css">
<!--
.agreement {
border: 1px solid #666666;
}
.green {
color: #00CC00;
font-weight: bold;
}
.red {color: #FF0000; font-weight: bold; }
#scroll {
border: 1px solid #0000FF;
line-height: 25px;
height: 25px;
width: 280px;
text-align: left;
}
.red{
background-color:#999999;
text-align: center;
filter:Alpha(opacity=80);/*透明度*/
}
#act {
background-image: url([img]yun_qi_img/loading.gif[/img]);
height: 27px;
width: 282px;
}
-->
</style>
<script>
var MyMar;
function monitoring()
{
if(document.readyState =='complete')
{
window.location='?i='+query_get();
}
}
function query_get()
{
var querystr = window.location.href.split("=");
if(!Number(querystr[1]))
{
var value=0;
}else{
var value=Number(querystr[1]);
}
return Number(value)+1;
}
MyMar=setInterval('monitoring()',3000);
</script>
<div style="text-align: center;" id=all_a>
<div align="center" id=act>
<div align="center" id=scroll>
<div class="red" style="width:1%;"></div>
</div>
</div>
</div>
<div align="center">
正在檢索:<span id=link></span>
</div>
<div id="logs" class="agreement" style="height:420px; overflow:auto;">
<?
/*===========================================================
= 著作權協議:
= GPL ()
=------------------------------------------------------------
= 摘 要:URL收集合函式 PHP5
= 版 本:1.0
=------------------------------------------------------------
= 開源stal 項目組
= 更新作者:jd808
= 最後日期:2008-4-18
============================================================*/
$file='sitemap.xml'; //GOOGLE 需要的檔案 執行時則做首頁的臨時URL隱藏檔
$temp_file='temp.xml';//內頁URL臨時隱藏檔
$url="http://www.gyqpw.com/"; //要搜尋的網站
$timea=time();//開始時間 使用者無需理它 只管上面3個參數即可
if(!$_GET['i'])
{
file_put_contents($file,'');
file_put_contents($temp_file,'');
file_put_contents($file,con($url,$timea));
echo "<script>
window.location='?i=bak';
</script>";
}else{
consts($_GET['i'],$timea,$file,$url);
}
function con($url,$timea) //控制
{
echo "<script>
document.getElementById('link').innerHTML='正在收集 ".$url." 的資訊!';
</script>";
$str = file_get_contents($url);
$collection_url=collection_url($str,$url);
$collection_url=array_flip($collection_url);
foreach($collection_url as $key=>$value)
{
if(count(explode($url,$key))==2)
{
$strurl.=$key."\n";
}
}
return $strurl;
}
function consts($i,$timea,$file,$urlys)
{
$str =file_get_contents($file); //讀取頁面資料並生產字串
$url=explode("\n",$str);
$sum=count($url)-1;
if($i=='bak')
{
$i=0;
}
/*進度條*/
$wid=round($i/$sum*100,2)."%";
$div="<div class='red' style='width:".$wid.";'>$wid</div>";
echo '<script>
document.getElementById("scroll").innerHTML="'.$div.'";
</script>';
ob_flush();//釋放緩衝
flush(); //將不再緩衝裡的資料發送到瀏覽器去
/*進度條END */
for($j=$i;$j<$sum;$j++)
{
if(!$url[$j])
{
continue;
}
if(!detection_url($url[$j])) //檢測URL是否合法
{
continue;
}
$timeb=time();//跟蹤時間
if(($timeb-$timea)>=25)
{
memory($collection_url,$j); //儲存資料
}
/* URL顯示跟蹤*/
echo "<script>
document.getElementById('link').innerHTML='".$url[$j]."';
</script>";
ob_flush();//釋放緩衝
flush(); //將不再緩衝裡的資料發送到瀏覽器去
/* URL顯示跟蹤END*/
$urlstr=@file_get_contents($url[$j]);
$collection_url[]=collection_url($urlstr,$urlys);
$timec=time();//跟蹤時間
if(($timec-$timea)>=25)
{
memory($collection_url,$j); //儲存資料
}
if($j==$sum-1)
{
memorys(); //儲存資料 主要是產生正式的xml
}
}
}
function collection_url($str,$url) //收集URL並返回一個數組(以頁面為主)
{
preg_match_all('/<a.*?href="(.+?)"/is',$str,$matches);
$urlexp=$matches[1];
for($j=0;$j<count($urlexp);$j++)
{
$urlexp[$j]=ltrim(str_replace("\r\n",'',$urlexp[$j]));
$urlexp[$j]=ltrim(str_replace("\n",'',$urlexp[$j]));
$urlexp[$j]=ltrim(str_replace("\r",'',$urlexp[$j]));
if($urlexp[$j]=='#')
{
continue;
}
if($urlexp[$j]=='/#')
{
continue;
}
if(!strchr($urlexp[$j],'http://'))
{//沒有http://
$urlall[]=$url.$urlexp[$j];
echo $url.$urlexp[$j].'<br>';
print "<script>document.getElementById('logs').scrollTop = document.getElementById('logs').scrollHeight;</script>";
ob_flush();//釋放緩衝
flush(); //將不再緩衝裡的資料發送到瀏覽器去
}else{
if(count(explode($url,$urlexp[$j]))==2)
{
$urlall[]=$urlexp[$j];
echo $urlexp[$j].'<br>';
print "<script>document.getElementById('logs').scrollTop = document.getElementById('logs').scrollHeight;</script>";
ob_flush();//釋放緩衝
flush(); //將不再緩衝裡的資料發送到瀏覽器去
}else{
unset($urlexp[$j]);
}
}
}
return $urlall; //返回本頁面搜尋所得到的數組
}
function memory($collection_url,$i)
{
global $temp_file;
if(is_array($collection_url))
{
for($h=0;$h<count($collection_url);$h++)
{
for($l=0;$l<count($collection_url[$h]);$l++)
{
$strts.=$collection_url[$h][$l]."\n";
}
}
$wstr=file_get_contents($temp_file);
file_put_contents($temp_file,$wstr.$strts);
if($i==0)
{
$i=2;
}
$k=$i-1;
echo "<script>
window.location='?i=".$k."';
</script>";
exit;
}
}
function memorys() //主要是產生正式的xml
{
global $temp_file,$file;
$file_arr=array_flip(file($file));
$temp_file_arr=array_flip(file($temp_file));
$xmla='<?xml version="1.0" encoding="UTF-8"?>'."\r\n".'<urlset xmlns="'">http://www.google.com/schemas/sitemap/0.84">';
$xmlc="\r\n</urlset>";
foreach($file_arr as $keya=>$valuea)
{
$keya=ltrim(str_replace("\r\n",'',$keya));
$keya=ltrim(str_replace("\n",'',$keya));
$keya=ltrim(str_replace("\r",'',$keya));
$xml.='<url>
<loc>'.$keya.'</loc>
<lastmod>'.date("Y-m-d",time()).'</lastmod>
<changefreq>daily</changefreq>
</url>';
}
foreach($temp_file_arr as $keyb=>$valueb)
{
$keyb=ltrim(str_replace("\r\n",'',$keyb));
$keyb=ltrim(str_replace("\n",'',$keyb));
$keyb=ltrim(str_replace("\r",'',$keyb));
$xml.='<url>
<loc>'.$keyb.'</loc>
<lastmod>'.date("Y-m-d",time()).'</lastmod>
<changefreq>daily</changefreq>
</url>';
}
$strts=$xmla.$xml.$xmlc;
file_put_contents($file,$strts);
echo "<script>
clearInterval(MyMar);
document.getElementById('link').innerHTML='URL已經收集完成!';
document.getElementById('all_a').innerHTML='<b>XML產生已完成!</b>';
</script>";
}
function detection_url($url)
{
if(strrchr($url,'='))
{
return true;
}
if(substr($url,strlen($url)-1,1)=='/')
{
return true;
}
$postfix= strrchr($url,'.');
switch ($postfix)
{
case ".php":
return true;
break;
case ".html":
return true;
break;
case ".htm":
return true;
break;
case ".asp":
return true;
break;
case ".aspx":
return true;
break;
case ".shtml":
return true;
break;
}
return false;
}
?>
</div>