<?php /* * SiteMap接口类 */ class SitemapAction extends Action{ private static $baseURL = ''; //URL地址 private static $askMobileUrl = 'http://m.xxx.cn/ask/'; //问答移动版地址 private static $askPcUrl = "http://www.xxx.cn/ask/"; //问答pc地址 private static $askZonePcUrl = "http://www.xxx.cn/ask/jingxuan/"; //问答精选Pc链接 private static $askZoneMobileUrl = "http://m.xxx.cn/ask/jx/"; //问答精选移动版链接 //问答setmaps public function askSetMap(){ header('Content-type:text/html;charset=utf-8'); //获取问题列表 $maxid = 0; //索引文件最大id $minid = 0; //索引文件最小id $psize = 1000; //数据库每次取数量 $maxXml = 5000; //xml写入记录数量 $where = array(); //读取索引文件 $index = APP_PATH.'setmapxml/Index.txt'; //关联setmaps路径 $askXml = "../siteditu/ask/ask.xml"; if(!file_exists($index)){ $fp=fopen("$index", "w+"); if ( !is_writable($index) ){ die("文件:" .$index. "不可写,请检查!"); }먼저 1000개의 데이터를 꺼내고(나중에 수정하기 위해 유연하게 저장할 수 있음) 루프에서 xml 형식 파일을 생성합니다. file_puts_contens는 파일을 씁니다. 그런 다음 생성된 xml 파일 이름, 검색된 질문의 최소 ID, 검색된 질문의 최대 ID 및 검색된 질문 수를 인덱스 쿼리용 txt 파일에 작성합니다. 형식은 대략 다음과 같습니다. 0,3146886,3145887,1000마지막 숫자가 1000인 것을 확인하셨나요? 처음 선택하실 때 1000개의 데이터를 꺼내서 0.xml 파일에 적어주세요. 추출된 xml 파일 이름, 최소 ID, 최대 ID, 항목 수를 인덱스 쿼리 txt에 씁니다. 처음으로 0.xml에 1,000개의 데이터가 기록되었고, 생성된 데이터의 개수는 1,000개였습니다. 두 번째로 쿼리할 때 select 문이 됩니다. 여기서 id > 꺼낸 최대 id (현재 mysql은 정방향 쿼리이고, 역순이면 이하로 변경) Limit 1000 이 경우에는 1000을 더 빼낸 후 최소 id와 최대값을 빼냅니다. 인덱스 쿼리 txt의 id가 수정되어 생성된 항목 수가 2000개로 추가됩니다. 비유하자면 생성된 항목 수가 5000개에 도달하면 0,3146886,3145887,5000 1,3148886,3147887,1000과 유사하게 인덱스 파일에 또 다른 줄을 작성합니다. 이렇게 작성하면 서버에 대한 부담이 줄어듭니다.
<?php class GeoHelper { /** * @param int $lat1 * @param int $lon1 * @param int $lat2 * @param int $lon2 * @param string $unit * @return */ public static function distance($lat1, $lon1, $lat2, $lon2, $unit = "K") { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad ($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { //mi return $miles; } } /** * * @param string $address * @param string $apikey * @return array [1]:lat [0]:lng */ public static function getLatLng($address, $apikey) { $find = array("\n", "\r", " "); $replace = array("", "", "+"); $address = str_replace($find, $replace, $address); $url = 'http://maps.google.com/maps/geo?q=' . $address . '&key=' . $apikey . '&sensor=false&output=xml&oe=utf8'; $response = self::xml2array($url); $coordinates = $response['kml']['Response']['Placemark']['Point']['coordinates']; if (!empty($coordinates)) { $point_array = split(",", $coordinates); return $point_array; } } }Google 지도를 사용하여 지도의 두 지점 사이의 거리를 계산하세요
<?php /** * Created by PhpStorm. * User: jifei * Date: 15/6/25 * Time: 下午2:26 */ class Pinyin { //中文字符串 private static $string = ''; //拼音 private static $pinyin = ''; private static $encoding = 'UTF-8'; //短拼音 private static $short_pinyin = ''; //单个汉字拼音的字典 private static $dic = array(기본 전용 기능은 변환 + 첫 문자 반환 여부입니다. 확장 후 지원1. 반환 형식 [모두: 전체 병음|첫 번째: 첫 글자|1: 첫 번째 문자의 첫 글자만]2. 인식할 수 없는 문자 대체를 위한 자리 표시자(원본은 하드 코딩됨 _ ) 3. 한자가 아닌 문자에 대한 일반 제어 허용(원본 버전에서는 0-9a-zA-Z가 하드 코딩되어 있으며 공백은 지원되지 않음)압축 후 pinyin.php ~ 206KB UTF8 글꼴 라이브러리를 사용합니다. 확장하면 106K만 남습니다. 물론 성능도 그의 10,000회 스트레스 테스트에서 2.4초, 확장 후 2.8초 손실은 0.4초에 불과하므로 무시할 수 있습니다.
<?php class Logic_BlackWord { const APP_FORUM = 1; const APP_BLOG = 2; const APP_VOTE = 3; public function getHitList($txt) { $hitList = array(); //对禁词分批过滤 $max = $this->getMax(); if($max) { $size = 1000; $last = ceil($max/$size); for($page=1;$page<=$last;$page++) { $result = $this->getHitListByPage($txt,$page,$size); if($result) $hitList = array_merge($hitList,$result); } } 주로 int substr_count ( string haystack, string needle [, int offset [, int length]] )를 사용하는 이 방법은 테스트할 문자열 $str을 순회하여 $allergicWord에 민감한 단어가 포함되어 있는지 확인하는 방법입니다. 배열 단어:
<?php $_form = new formHtmlFind(); class formHtmlFind{ public function formHtml($array,$infoArray='') { if(empty($array))return false; $newform = null; $this->infoArray = !empty($infoArray)?$infoArray:array(); $this->array['class'] = get_class_methods(get_class()); foreach ($array as $key =>$arr) { $key = preg_replace("/[^a-z]/i",'',$key); $newform .= $this->outputForm($arr,$key); } return $newform.$this->jsError(); } private function outputForm($arr,$key) { $value = null; if(empty($arr))return false; // input Type $type = $key; // input NAME $name = trim($arr[0]);PHP 형식의 문자 필터링 클래스와 사용법입니다. 참고할 수 있도록 모든 사람과 공유하세요.
<? phpclass BaseLogic extends MyDB { protected $tabName; protected $fieldList; protected $messList; function add($postList) { $fieldList=''; $value=''; foreach ($postList as $k=>$v) { if(in_array($k, $this->fieldList)){ $fieldList.=$k.","; if (!get_magic_quotes_gpc()) $value .= "'".addslashes($v)."',"; else $value .= "'".$v."',"; } } $fieldList=rtrim($fieldList, ","); $value=rtrim($value, ","); $sql = "INSERT INTO {$this->tabName} (".$fieldList.") VALUES(".$value.")"; echo $sql; $result=$this->mysqli->query($sql); if($result && $this->mysqli->affected_rows >0 ) return $this->mysqli->insert_id; else return false; }데이터 처리를 위한 PHP 클래스입니다. 필요한 친구들은 다운받아서 사용하면 됩니다. 테이블 이름과 필드 세트, 함수는 Function: add($postList)Function: Add($postList)Function: Add Parameter: $postList 제출된 변수 목록Return: 새로 삽입된 자동 증가 ID 🎜🎜
<?php class SendM{ private $Mailhost,$Mailuser,$Mailpwd,$Mailport,$Mailtimeout,$ms,$ending = "\r\n",$endingc="\n"; function __construct($Mailhost,$Mailuser,$Mailpwd,$Mailport,$Mailtimeout){ $this->Mailhost=$Mailhost; $this->Mailuser=$Mailuser; $this->Mailpwd=$Mailpwd; $this->Mailport=$Mailport; $this->Mailtimeout=$Mailtimeout; $this->ConnectSmtpServer(); } private function ConnectSmtpServer(){ if(!is_string($this->Mailhost)){ settype(trim($this->Mailhost),"string"); } if(!is_integer($this->Mailport)){ settype(trim($this->Mailport),"integer"); } if(!is_integer($this->Mailtimeout)){ settype(trim($this->Mailtimeout),"integer"); } $this->ms=@fsockopen($this->Mailhost,$this->Mailport,$this->errorno,$this->errorstr,$this->Mailtimeout); if(substr(PHP_OS,0,3) != "WIN"){ stream_set_timeout($this->ms, $this->Mailtimeout, 0);} $rcp = $this->get_echo(); fputs($this->ms,"ehlo bobo".$this->ending); $rcp = $this->get_echo(); if(substr($rcp,0,3)!='250'){ return false; } fputs($this->ms,'auth login'.$this->ending); $rcp = $this->get_echo(); if(substr($rcp,0,3)=='334'){ $this->Auth($this->Mailuser,$this->Mailpwd); }else{ return false; } } private function Auth($Mailuser,$Mailpwd){ $this->Mailuseren=base64_encode($Mailuser); $this->Mailpwden=base64_encode($Mailpwd); fputs($this->ms,$this->Mailuseren.$this->ending); $rcp = $this->get_echo(); fputs($this->ms,$this->Mailpwden.$this->ending); $rcp = $this->get_echo(); } private function get_echo(){ $edata=""; while($estr=@fgets($this->ms,600)){ $edata .= $estr; if(substr($estr,3,1) == " ") { break; } } return $edata; } public function Send($to,$subject,$connect){ $host=explode('.',$this->Mailhost); $fromaddress=$this->Mailuser.'@'.$host[1].'.'.$host[2]; fputs($this->ms,'mail from:<'.$fromaddress.'>'.$this->ending); $rcp = $this->get_echo(); fputs($this->ms,'rcpt to:<'.$to.'>'.$this->ending); $rcp = $this->get_echo(); fputs($this->ms,'data'.$this->ending); $rcp = $this->get_echo(); fputs($this->ms,"to:$to".$this->endingc); fputs($this->ms,"from:$fromaddress".$this->endingc); fputs($this->ms,"subject:$subject".$this->endingc.$this->endingc); fputs($this->ms,"$connect".$this->endingc); fputs($this->ms,'.'.$this->ending); $rcp = $this->get_echo(); if(substr($rcp,0,3)=='250'){header("Location:main_pro.php?act=msg&errors=on&msg=邮件发送成功!已成功提交至对方服务器!"); }else{ header("Location:main_pro.php?act=msg&errors=on&msg=很遗憾,邮件发送失败了!请检查邮件账户配置是否正确!"); } } } ?>이메일 보내기를 위한 PHP 클래스입니다. 필요한 친구들은 다운로드해서 사용할 수 있습니다. 사용 지침: $m= new SendM('smtp 서버 주소', '계정', '비밀번호', 포트(int), 시간 초과 재시도 시간(int)) $m->Send( '받는 사람의 이메일','제목','이메일 내용');사용 예:$m= new SendM('smtp.yeah.net','testuser','testuserpwd',25,30 ); $m->Send('a@coolmr.com','테스트 이메일','이메일 발송을 위한 테스트 이메일입니다. 지원해 주셔서 감사합니다.');
<?php class emp { var $name; var $address; var $dept; function assign_info($n,$a,$d) { $this->name=$n; $this->state=$a; $this->dept=$d; } function display_info() { echo("<p>Employee Name : $this->name"); echo("<p>State : $this->state"); echo("<p>Department : $this->dept"); } } $empobj = new emp; $empobj->assign_info("kaka lname","California","Accounts"); echo("<center><h2>Displaying Employee Information</h2></center>"); echo("<font size=4>"); $empobj->display_info(); echo("</font>"); ?>이것은 정의하고 사용하는 PHP 클래스입니다. 필요한 친구들은 다운로드하여 사용할 수 있습니다.
<?php defined('ACC')||exit('Access Denied'); // 封装mysql操作类,包括连接功能,及查询功能. class mysql extends absdb{ protected static $ins = null; protected $host; // 主机名 protected $user; // 用户名 protected $passwd; // 密码 protected $db; // 数据库名 protected $port; // 端口 protected $conn = null; // 在内部操作,获得一个对象 public static function getIns() { if(self::$ins === null) { self::$ins = new self(); } $conf = conf::getIns(); self::$ins->host = $conf->host; self::$ins->user = $conf->user; self::$ins->passwd = $conf->pwd; self::$ins->db = $conf->db; self::$ins->port = $conf->port; self::$ins->connect(); self::$ins->select_db(); self::$ins->setChar(); return self::$ins; } // 不让外部做new操作, protected function __construct() { } // 连接数据库 public function connect() { $this->conn = @mysql_connect($this->host,$this->user,$this->passwd,$this->port); if(!$this->conn) { $error = new Exception('数据库连不上',9); throw $error; } } // 发送sql查询 public function query($sql) { $rs = mysql_query($sql,$this->conn); if(!$rs) { log::write($sql); } return $rs; }mysql을 싱글톤 모드로 구현한 PHP 클래스입니다. 필요한 친구들은 다운받아서 사용하면 됩니다.
<?php function ColorDarken($color, $dif=20){ $color = str_replace('#', '', $color); if (strlen($color) != 6){ return '000000'; } $rgb = ''; for ($x=0;$x<3;$x++){ $c = hexdec(substr($color,(2*$x),2)) - $dif; $c = ($c < 0) ? 0 : dechex($c); $rgb .= (strlen($c) < 2) ? '0'.$c : $c; } return '#'.$rgb; } //范例: for ($x=1; $x < 20; $x++){ // Start color: $c = ColorDarken('#FF481D', ($x * 3)); print "<div style='background-color: $c; color: $c; font-size: 50%; padding: 0px;'>.</div>\n"; } ?>색을 어둡게 하는 PHP 클래스입니다. 필요한 친구들은 다운받아서 사용하면 됩니다.
<?php class Backup { /** * @var stores the options */ var $config; /** * @var stores the final sql dump */ var $dump; /** * @var stores the table structure + inserts for every table */ var $struktur = array(); /** * @var zip file name */ var $datei; /** * this function is the constructor and phrase the options * and connect to the database * @return */ public function Backup($options) { // write options foreach($options AS $name => $value) { $this->config[$name] = $value; }이것은 전체 MySQL 데이터베이스에 대한 매우 유용한 PHP 백업 클래스입니다. 필요한 친구는 다운로드하여 사용할 수 있습니다
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /* |-------------------------------------------------------------------------- | File and Directory Modes |-------------------------------------------------------------------------- | | These prefs are used when checking and setting modes when working | with the file system. The defaults are fine on servers with proper | security, but you may wish (or even need) to change the values in | certain environments (Apache running a separate process for each | user, PHP under CGI with Apache suEXEC, etc.). Octal values should | always be used to set the mode correctly. | */ define('FILE_READ_MODE', 0644); define('FILE_WRITE_MODE', 0666); define('DIR_READ_MODE', 0755); define('DIR_WRITE_MODE', 0777); /* |-------------------------------------------------------------------------- | File Stream Modes |-------------------------------------------------------------------------- | | These modes are used when working with fopen()/popen() | */ define('FOPEN_READ','rb'); define('FOPEN_READ_WRITE','r+b'); define('FOPEN_WRITE_CREATE_DESTRUCTIVE','wb'); // truncates existing file data, use with care define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE','w+b'); // truncates existing file data, use with care define('FOPEN_WRITE_CREATE','ab'); define('FOPEN_READ_WRITE_CREATE','a+b'); define('FOPEN_WRITE_CREATE_STRICT','xb'); define('FOPEN_READ_WRITE_CREATE_STRICT','x+b'); /* End of file constants.php */ /* Location: ./application/config/constants.php */PHP 생성 및 온라인 브라우징 라이브러리입니다. 필요한 친구는 다운로드하여 사용할 수 있습니다.