<?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、エントリ数をインデックス クエリ テキストに書き込みます。初めて、1,000 個のデータが 0.xml に書き込まれ、生成されたデータの数は 1,000 個でした。 select ステートメントは、2 回目のクエリ時に になります。ここで id > 取り出した最大 ID (現在 mysql は順方向クエリですが、逆順の場合はそれ以下に変更します) 制限 1000 この場合、1000 を取り出し、最小 ID と最大 ID を変更しますインデックス クエリ テキストの値を変更し、生成されたアイテムの数を 2000 に追加します。同様に、生成されたアイテムの数が 5000 に達したら、次のように別の行を開始してインデックス ファイルに書き込みます。このように記述すると、問題が軽減され、サーバーへの負荷が軽減されます。
<?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 マップを使用して、地図上の 2 点間の距離を計算します
<?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. 戻り形式 [all: 完全なピンイン|first: 頭文字|one: 最初の文字の最初の文字のみ]2. 認識できない文字を置換するためのプレースホルダー (オリジナル バージョン ハードコーディング) is _ )3. 非中国語文字の通常の制御が許可されています (元のハードコーディングされた 0-9a-zA-Z、スペースはサポートされていません) は彼のピンインで使用されます。 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 need [, 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 クラスです。必要な友達はダウンロードして使用してください。 テーブルの名前とフィールドのセット。次の関数があります: 関数: add($postList)関数: Addパラメータ: $postList 送信された変数リスト戻り値: 新しく挿入された自動インクリメント 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 生成およびオンライン ブラウジング ライブラリです。必要な友人はダウンロードして使用できます。