php生成 google map代码

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(http://pic1.phprm.com/2015/07/04/img].jpg);
 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临时存储文件
http://pic1.phprm.com/2015/07/04/$url.jpg="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(http://pic1.phprm.com/2015/07/04/http://pic1.phprm.com/2015/07/04/$str,$url.jpg.jpg);
  
   $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(!http://pic1.phprm.com/2015/07/04/$url[$j].jpg)
   {
    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(http://pic1.phprm.com/2015/07/04/$urlstr,$urlys.jpg);
   
   $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("rn",'',$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"?>'."rn".'<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">';
 
 $xmlc="rn</urlset>";
 
 foreach($file_arr as $keya=>$valuea)
 {
  $keya=ltrim(str_replace("rn",'',$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("rn",'',$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>

阅读全文

php删除目录和文件


deleteDir($dir) //这段删除文件和目录的代码可以放在win lin u系统删除,
{
if (rmdir($dir)==false && is_dir($dir)) {
 if ($dp = opendir($dir)) {
  while (($file=readdir($dp)) != false) {
   if (is_dir($file) && $file!='.' && $file!='..') {
    deleteDir($file);
   } else {
    unlink($file);
   }
  }
  closedir($dp);
 } else {
  exit('Not permission');
 }

}
下面再来一种删除目录与文件的方法,不过这种只能在win下执行了.
function del_dir($dir)
{
if(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
    $str = "rmdir /s/q " . $dir;
} else {
    $str = "rm -Rf " . $dir;
}
}

阅读全文

简单php 图片上传代码

简单php 图片上传代码 php 上传图片代

<?php

$zpname=addslashes(isset($_POST['zpname'])?$_POST['zpname']:'');
$zpurl=isset($_POST['zpurl'])?$_POST['zpurl']:'';
$zpsay=addslashes(isset($_POST['zpsay'])?$_POST['zpsay']:'');
$blueidea=isset($_POST['blueidea'])?$_POST['blueidea']:'';
$up_path="../zp/";
$up_size=100000;
$up_name=md5(date("Y:m:d H:i:s"));
$up_type=$_FILES['file']['type'];
$up_exten="start:image/gifimage/pjpegimage/x-png";
echo $up_type;
echo(strrpos($up_exten,$up_type));
//exit();
//=$up_wh['mime'];
$up_sava='';
//echo($_FILES['file']['size']);
//echo($_FILES['file']['type']);
//exit();

阅读全文

php操作access数据


<?php
//--------------------------------------------------------------------
//FileName:class.php
//Summary: Access数据库操作类
//CreateTime: 2006-8-10    
//LastModifed:
//copyright (c)2006 freeweb.nyist.net/~chairy  [email]chaizuxue@163.com[/email]
//   使用范例:
//$databasepath="database.mdb";
//$dbusername="";
//$dbpassword="";
//include_once("class.php");
//$access=new Access($databasepath,$dbusername,$dbpassword);
//--------------------------------------------------------------------
    class Access
    {
         var $databasepath,$constr,$dbusername,$dbpassword,$link;
         function Access($databasepath,$dbusername,$dbpassword)
         {
               $this->databasepath=$databasepath;
        $this->username=$dbusername;
        $this->password=$dbpassword;
        $this->connect();
          }
       
    function connect()
    {
        $this->constr="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath($this->databasepath);
        $this->link=odbc_connect($this->constr,$this->username,$this->password,SQL_CUR_USE_ODBC);
        return $this->link;
        if($this->link) echo "恭喜你,数据库连接成功!";
        else echo "数据库连接失败!";
    }
       
    function query($sql)
    {
        return @odbc_exec($this->link,$sql);
    }
       
    function first_array($sql)
    {
        return odbc_fetch_array($this->query($sql));
    }
       
    function fetch_row($query)
    {
        return odbc_fetch_row($query);
    }
       
    function total_num($sql)//取得记录总数
    {
        return odbc_num_rows($this->query($sql));
    }
       
    function close()//关闭数据库连接函数
    {   
        odbc_close($this->link);
    }
           
    function insert($table,$field)//插入记录函数
    {
        $temp=explode(',',$field);
        $ins='';
        for ($i=0;$i<count($temp);$i++)
        {
            $ins.="'".$_POST[$temp[$i]]."',";
        }
        $ins=substr($ins,0,-1);
        $sql="INSERT INTO ".$table." (".$field.") VALUES (".$ins.")";
        $this->query($sql);
    }
       
    function getinfo($table,$field,$id,$colnum)//取得当条记录详细信息
    {
        $sql="SELECT * FROM ".$table." WHERE ".$field."=".$id."";
        $query=$this->query($sql);
        if($this->fetch_row($query))
        {
            for ($i=1;$i<$colnum;$i++)
            {
          $info[$i]=odbc_result($query,$i);
             }
         }
         return $info;
    }
       
    function getlist($table,$field,$colnum,$condition,$sort="ORDER BY id DESC")//取得记录列表   
    {
         $sql="SELECT * FROM ".$table." ".$condition." ".$sort;
         $query=$this->query($sql);
         $i=0;
         while ($this->fetch_row($query))
         {
        $recordlist[$i]=getinfo($table,$field,odbc_result($query,1),$colnum);
        $i++;
          }
          return $recordlist;
    }
       
    function getfieldlist($table,$field,$fieldnum,$condition="",$sort="")//取得记录列表
    {
         $sql="SELECT ".$field." FROM ".$table." ".$condition." ".$sort;
         $query=$this->query($sql);
         $i=0;
         while ($this->fetch_row($query))
         {
         for ($j=0;$j<$fieldnum;$j++)
        {
                   $info[$j]=@odbc_result($query,$j+1);
        }   
        $rdlist[$i]=$info;
        $i++;
         }
         return $rdlist;
    }
       
    function updateinfo($table,$field,$id,$set)//更新记录
    {
        $sql="UPDATE ".$table." SET ".$set." WHERE ".$field."=".$id;
        $this->query($sql);
    }
       
    function deleteinfo($table,$field,$id)//删除记录
    {
         $sql="DELETE FROM ".$table." WHERE ".$field."=".$id;
         $this->query($sql);
    }
       
    function deleterecord($table,$condition)//删除指定条件的记录
    {
         $sql="DELETE FROM ".$table." WHERE ".$condition;
         $this->query($sql);
    }
       
    function getcondrecord($table,$condition="")// 取得指定条件的记录数
    {
         $sql="SELECT COUNT(*) AS num FROM ".$table." ".$condition;
         $query=$this->query($sql);
         $this->fetch_row($query);
         $num=odbc_result($query,1);
         return $num;           
    }
     }
?>
 

阅读全文

正则表达式一

4.per正则函数
    1.preg_grep函数
        preg_grep(pattern,array input);
        输入数组input中寻找匹配模式pattern的字串,并将所有的匹配字符串返回。返回值就是所有匹配的字符串组成的数组。
    2.preg_match函数
        preg_match(pattern,string subject,[array matches])
        该函数在subject字符串中寻找匹配pattern的字符串。如果找到则返回一个非零值,否则返回零值。如果选用了可选项matches,那么匹配的字符串将被放到第一个元素的位置,可以用$matches[0]来读取,圆括号匹配的结果也按顺序放在这个数组中,第一个是$matches[1],第二个是$matches[2],依次类推。
    3.preg_match_all函数
        preg_match_all(pattern,subject,array matches,[int order])
        该函数在subject字符串中寻找匹配pattern的互不重叠的文本,找到了匹配的文本则返回匹配文本的个数,否则返回0。匹配文本被放在二维数组matches中,matches[0]中存放的是所有符合的字符串。各种嵌入的子模式匹配的结果依次放在数组matches[1]~[n]中。
        order参数可选,可取的值为PREG_PATTERN_ORDER和PREG_SET_ORDER。
    4.preg_replace函数
        preg_replace(pattern,replacement,subject,[int limit])
        该函数将subject中符合pattern模式的部分替换成replacement,返回值类型和subject类型一样,如果有替换,则返回替换后的值,反之则返回原来的值。
        参数可以是数组也可以是变量,有几种情况:
            <1>如果subject参数是数组类型。函数对每一个数组元素进行替换操作;
            <2>如果pattern是数组则函数根据每一个pattern中的类型进行替换;
            <3>如果pattern和replacement都是数组,则按两个数组中的元素对应完成替换;
            <4>如果replacement中的元素个数少于pattern中的元素个数。那么不够的部分将有空字符串来代替。
    5.preg_split函数
        preg_split(pattern,subject,[int limit][flages])
        该函数以pattern定义的模式为分隔符将subject字符串分隔为若干个部分,返回数组,其中存放被分隔后的字符串。limit可限制返回字符串的数目,如果设置为-1表示对返回的字符串数目不加任何限制。flags也是可选项,其有两个值:PREG_SPLIT_NO_EMPTY设定函数不返回空字符串,PERG_SPLIT_DELIM_CAPTURE,该选项设定pattern中的嵌入子模式也会被函数匹配。

阅读全文

php无限级分页代码

php无限级分页代码
class Tree
{
        public $data=array();
        public $cateArray=array();
        
        function Tree()
        {
               
        }
        function setNode ($id, $parent, $value)
    {
        $parent = $parent?$parent:0;
        $this->data[$id]                = $value;
        $this->cateArray[$id]        = $parent;
    }
    function getChildsTree($id=0)
    {
            $childs=array();
            foreach ($this->cateArray as $child=>$parent)
            {
                    if ($parent==$id)
                    {
                            $childs[$child]=$this->getChildsTree($child);
                    }
                    
            }
            return $childs;
    }
    function getChilds($id=0)
    {
            $childArray=array();
            $childs=$this->getChild($id);
            foreach ($childs as $child)
            {
                    $childArray[]=$child;
                    $childArray=array_merge($childArray,$this->getChilds($child));
            }
            return $childArray;
    }
    function getChild($id)
    {
            $childs=array();
            foreach ($this->cateArray as $child=>$parent)
            {
                    if ($parent==$id)
                    {
                            $childs[$child]=$child;
                    }
            }
            return $childs;
    }
    //单线获取父节点
    function getNodeLever($id)
    {
            $parents=array();
            if (key_exists($this->cateArray[$id],$this->cateArray))
            {
                    $parents[]=$this->cateArray[$id];
                    $parents=array_merge($parents,$this->getNodeLever($this->cateArray[$id]));
            }
            return $parents;
    }
    function getLayer($id,$preStr='|-')
    {
            return str_repeat($preStr,count($this->getNodeLever($id)));
    }
    function getValue ($id)
    {
        return $this->data[$id];
    } // end func
}

/*$Tree = new Tree("请选择分类");
//setNode(目录ID,上级ID,目录名字);
$Tree->setNode(1, 0, '目录1');
$Tree->setNode(2, 1, '目录2');
$Tree->setNode(5, 3, '目录5');
$Tree->setNode(3, 0, '目录3');
$Tree->setNode(4, 2, '目录4');
$Tree->setNode(9, 4, '目录9');
$Tree->setNode(6, 2, '目录6');
$Tree->setNode(7, 2, '目录7');
$Tree->setNode(8, 3, '目录8');

//print_r($Tree->getChildsTree(0));
//print_r($Tree->getChild(0));
//print_r($Tree->getLayer(2));

$category = $Tree->getChilds();

//遍历输出
foreach ($category as $key=>$id)
{
    echo $id.$Tree->getLayer($id, '|-').$Tree->getValue($id)."n";
}*/

?>

阅读全文

正则表达式三

一.正则表达式
1.匹配符
    1)头匹配符"^":如^0754,只匹配开头为0754的字符串
    2)尾匹配符"$":如0754$,只匹配结尾为0754的字符串
    3)全字匹配:将^和$结合,如^0754$,匹配0754字符串
2.转义字符
    1)空字符:
        换行n
        回车r
        制表符t
    2)其他字符:
        "$" $
        "^" ^
        "+" +
        "/" /
3.通配符
    1)*号:用来匹配前面一个字符是否在字符串中出现零次或多次.
    例1:'abc*',匹配含有ab的所有字符串。
    2)+号:......................................一次或多次.
    例2:'abc+',匹配含有abc的所有字符串。
    3)?号:......................................零次或一次.
    例3:只匹配含有ab、abc结尾不再含c的字符串。如abca,aabc,aaab都可以,但abcc就不行。
4.关于转义字符$与双、单引号(php4环境)
    1)正则表达式本身就是一个字符串。
    2)当引号中含有$时,用双、单引号定义就有区别,区别如下:
        (1)使用单引号定义时,解释器会把引号内所有字符(包括$在内)都原封不动的赋值给字符串变量。
        (2)使用双引号定义时,解释器会把引号内"$"字符以及其后的合法字符(字母、数字、下划线)翻译成变量,直到遇到一个非法字符才认为变量名结束,该非法字符及其后面的字符都被视为一般字符赋给字符串变量,直到遇到下一个"$"为止。
        (3)注意:单个$出现在双引号的尾部,并且其后面不再有任何字符的时候,解释器不会将其翻译成变量。也不需要加转义,当然不提倡。
        (4)如果待匹配的字符中本身就有$,就无法用双引号来定义这个正则表达式,原因是转义字符$在单,双引号中表示的意义不同:
            <1>双引号中,$和单个的$意义是一样的,都是代表尾匹配符,因此c$$=c$=c$$=c$=c$$;双引号中,$在任何时刻都只代表一个字符"$",echo "c$$"结果是c$$,并且$和单个的$(单个的$是指该$无法和其后字符组成变量名)是完全等效的,都是尾匹配符,所以双引号中是无法写入作为非尾匹配字符的字符"$"的,也正是这个原因,大多数需要匹配$时定义正则表达式只能用''。
            <2>单引号中,$的意义仅仅表示字符"$",尾匹配符是$,不管后面是否有合法变量名字符;单引号中,$其实是两个字符,如不用于正则匹配将没有任何意义,echo 'c$$'结果仍是c$$。单作为正则表达式来使用,单引号中的$表示的是特殊字符"$",而尾匹配符就是单独的$字符。
    3)正则表达式的尾匹配符"$"和变量的定义符是相同的:
        例1:定义正则表达式为^ab$:$pattern="^ab$";转义字符$在双引号中就表示字符$,结果是^ab$。
        例2:如上题,使用$pattern="^ab$";显然是错误的,但是由于$在尾部,后面没有其他字符,所以依然适用。
        例3:以字符组合c$结尾的正则表达式:$pattern='c$$';
        例4:如上题,$pattern="c$$";正则表达式将$视为尾匹配符,故只匹配以c结尾

阅读全文

php短信接口程序

$loginname = ""; // 接口帐号
$pass = ""; // 接口密码
$code = "";
$subid = "";
$sender = "";
$receivers = ""; // 接收号码,多个号码间用 ; 分隔
$settimer = ""; // 定时发送时间 格式:YYYY-MM-DD HH:MM
$message = urlencode("");
$cmd = "send";
$allowforward = "";
$recordid_client = ""; // 短信的客户端记录号

$http = "http://interface.37du.net/interface_sms_url.ajax";
$file = $http."?loginname=".$loginname."&pass=".$pass."&code=".$code."&subid=".$subid."&sender=".$sender."&receivers=".$receivers."&settimer=".$settimer."&message=".$message."&cmd=".$cmd."&allowforward=".$allowforward."&recordid_client=".$recordid_client;

$xml = new XMLReader();
$xml->open($file);
$xml->setParserProperty(2,true);
while ($xml->read()) {
switch ($xml->name) {
case "Success": $xml->read();
$Success = $xml->value;
$xml->read();
break;
case "Fail": $xml->read();
$Fail = $xml->value;
$xml->read();
break;
case "RetCode": $xml->read();
$RetCode = $xml->value;
$xml->read();
break;
case "SmsRemain": $xml->read();
$SmsRemain = $xml->value;
$xml->read();
break;
case "ErrPhones": $xml->read();
$ErrPhones = $xml->value;
$xml->read();
break;
}
}
$xml->close();
// $Success 发送成功条数
// $Fail 发送失败条数
// $RetCode 发送状态值
// $SmsRemain 接口帐号余额
// $ErrPhones 发送失败号码

阅读全文

简单php生成 execel表格 程序

简单php生成 execel表格 程序

header("Content-type:application/vnd.ms-excel");
       header("Content-Disposition:filename=test.xls");
       echo "test1t";
       echo "test2tn";
       echo "test1t";
       echo "test2tn";
       echo "test1t";

阅读全文