Time of Update: 2016-07-25
if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 8.0")) echo "Internet Explorer 8.0"; // 這裡可以寫其他的執行命令 else if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 7.0")) echo "Internet Explorer 7.0"; else
Time of Update: 2016-07-25
在web開發中,可以通過檔案快取,大大緩解資料庫的壓力。 如下代碼是php中使用檔案快取的例子。 CacheLayer.php class CacheLayer{ protected $root = ""; protected $cache = ""; protected $key = ""; protected $life = 0; public function __construct($key, $root = "/cachelayer"){
Time of Update: 2016-07-25
/*** 上傳圖片*/class imgUpload{ static protected $a; protected $formName; //表單名稱 protected $directory; //檔案上傳至目錄 protected $maxSize; //最大檔案上傳大小 protected $canUpload; //是否可以上傳
Time of Update: 2016-07-25
class DateFormat{ private static $_DIFF_FORMAT = array( 'DAY' => '%s天前', 'DAY_HOUR' => '%s天%s小時前', 'HOUR' => '%s小時', 'HOUR_MINUTE' => '%s小時%s分前', 'MINUTE' => '%s分鐘前',
Time of Update: 2016-07-25
可解壓縮zip檔案。它有兩個參數:壓縮檔的路徑、目標檔案的路徑。 function unzip_file($file, $destination) { // create object $zip = new ZipArchive() ; // open archive if ($zip->open($file) !== TRUE) { die ('Could not open
Time of Update: 2016-07-25
class Verify{ /** * 驗證使用者名稱 * @param string $value * @param int $length * @return boolean */ public static function isNames($value, $minLen=2, $maxLen=20, $charset='ALL'){ if(empty($value)) return false; switch($charset)
Time of Update: 2016-07-25
通過使用此程式碼片段,您可以很容易地提取任何網頁上的所有連結。 $html = file_get_contents('http://www.example.com'); $dom = new DOMDocument(); @$dom->loadHTML($html); // grab all the on the page $xpath = new DOMXPath($dom); $hrefs = $xpath->
Time of Update: 2016-07-25
一個很簡單的功能,從一個PHP數組產生一個.csv檔案。此函數使用 fputcsv PHP 內建函數產生逗點分隔檔(.CSV)。該函數有3個參數:資料,分隔字元和CSV enclosure,預設是雙引號。 function generateCsv($data, $delimiter = ',', $enclosure = '"') { $handle = fopen('php://temp', 'r+'); foreach ($data as $line)
Time of Update: 2016-07-25
/** * 獲得檔案的mime type類型 * @author xiaobing.meng * */class MimeTypes {public static $mime_types = array ('apk' => 'application/vnd.android.package-archive','3gp' => 'video/3gpp', 'ai' => 'application/postscript', 'aif' => 'audio/x-aiff',
Time of Update: 2016-07-25
// f(ucking) u(ncrackable) e(ncryption) function by BlackHatDBL (www.netforme.net) function fue($hash,$times) { // Execute the encryption(s) as many times as the user wants for($i=$times;$i>0;$i--) { // Encode
Time of Update: 2016-07-25
function send_mail ($title,$content,$from,$to,$charset='gbk',$attachment =''){ include '/class/PHPMail.class.php'; //百度兩下 header('Content-Type: text/html; charset='.$charset); $mail = new PHPMailer(); $mail->CharSet =
Time of Update: 2016-07-25
/** * 匯出資料為excel表格 *@param $data 一個二維數組,結構如同從資料庫查出來的數組 *@param $title excel的第一列名,一個數組,如果為空白則沒有標題 *@param $filename 下載的檔案名稱 *@examlpe $stu = M ('User'); $arr = $stu -> select(); exportexcel($arr,array('id','賬戶','密碼','暱稱')
Time of Update: 2016-07-25
// 指定檔案路徑和縮放比例 $filename = 'test.jpg'; $percent = 0.5; // 指定標頭檔Content typezhi值 header('Content-type: image/jpeg'); // 擷取圖片的寬高 list($width, $height) = getimagesize($filename); $newwidth = $width * $percent; $newheight = $height * $percent; // 建立一個圖片。
Time of Update: 2016-07-25
//fsocket類比post提交$purl = "http://www.baidu.com";print_r(parse_url($url));sock_post($purl, "parm=ping");//fsocket類比get提交function sock_get($url, $query){ $info = parse_url($url); $fp = fsockopen($info["host"], 80, $errno, $errstr, 3); $head
Time of Update: 2016-07-25
function ezip($zip, $hedef = ''){ $dirname=preg_replace('/.zip/', '', $zip); $root = $_SERVER['DOCUMENT_ROOT'].'/zip/'; // echo $root. $zip; $zip = zip_open($root . $zip); // var_dump($zip); @mkdir($root . $hedef .
Time of Update: 2016-07-25
$i = imagecreatefromjpeg("image.jpg");for ($x=0;$x for ($y=0;$y $rgb = imagecolorat($i,$x,$y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> & 0xFF; $b = $rgb & 0xFF; $rTotal += $r; $gTotal += $g;
Time of Update: 2016-07-25
最近在做的項目有一項需要耗時任務在後台啟動並執行功能,雖然PHP並不是非常適合做常駐背景守護進程,但是由於項目主要代碼都是基於PHP實現,如 果運行在背景守護進程改換別的語言會非常不方便。所以不可避免會涉及到Web端和Daemon部分的通訊,Socket是一個不錯的方式。 Socket是什麼 socket的英文原義是“孔”或“插座”。作為BSD
Time of Update: 2016-07-25
function auto_save_image($body){$img_array = explode('&',$body);/*$img_array = array();preg_match_all("/(src)=[\"|\'| ]{0,}(http:\/\/(.*)\.(gif|jpg|jpeg|bmp|png))[\"|\'| ]{0,}/isU", $body, $img_array);$img_array = array_unique($img_array[2]);*/
Time of Update: 2016-07-25
class encryptCalss{ var $key=12; function encode($txt){ for($i=0;$i $txt[$i]=chr(ord($txt[$i])+$this->key); } return $txt=urlencode(base64_encode(urlencode($txt))); } function decode($txt){
Time of Update: 2016-07-25
php類實現完整備份資料庫,或者備份資料庫中指定表的功能: class Backup { /** * @var stores the options */ var $config; /** * @var stores the final sql dump */