Time of Update: 2016-07-25
function generateCsv($data, $delimiter = ',', $enclosure = '"') { $handle = fopen('php://temp', 'r+'); foreach ($data as $line) { fputcsv($handle, $line, $delimiter, $enclosure); } rewind($handle); while (!feof($handle)) {
Time of Update: 2016-07-25
function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) { $theta = $longitude1 - $longitude2; $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) *
Time of Update: 2016-07-23
/** * @author Administrator * */class TestGenerate {public static $appFolder = "";public static $ignoreFilePaths = array ("xxxx/xxx.php" );public static function start() {$AppPath = "E:\\myApp";TestGenerate::$appFolder = $AppPath;$destManifestPath
Time of Update: 2016-07-25
由於項目需要,需要本機伺服器接收資料後,再將資料轉寄到另外一台伺服器上,故要用到類比post請求發送資料,當然資料中也包含檔案流。 curl是php比較常用的方式之一,一般代碼如下: $params1 = "test"; $params2 = "@".$absolute_path;//如果是檔案 則參數為"@"+絕對路徑 $post_data = array( 'params1' => $params1,
Time of Update: 2016-07-23
一、json_encode() 該函數主要用來將數組和對象,轉換為json格式。先看一個數群組轉換的例子: $arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); echo json_encode($arr); 複製代碼 結果為 {"a":1,"b":2,"c":3,"d":4,"e":5} 複製代碼 再看一個對象轉換的例子: $obj->body = 'another post';
Time of Update: 2016-07-25
function detect_city($ip) { $default = 'UNKNOWN'; $curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)'; $url =
Time of Update: 2016-07-25
一次壓縮多個CSS檔案 header('Content-type: text/css');ob_start("compress");function compress($buffer) {/* remove comments */$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);/* remove tabs, spaces, newlines, etc. */$buffer =
Time of Update: 2016-07-25
if ( !isset($_REQUEST["url"]) ) exit; $u = $_REQUEST["url"]; if (substr($u, -0, 7) != "http://") exit; echo file_get_contents( $u );/* function getPage($url, $referer, $timeout, $header=true){ if(!isset($timeout)) $timeout=30;
Time of Update: 2016-07-25
1 給圖片進行浮水印添加 2產生一個新的縮率圖 class Image{ //浮水印配置項 private $waterOn; private $waterImg; private $waterPos; private $waterPct; private $waterText; private $waterFont; private $waterTextSize;
Time of Update: 2016-07-25
class SysCrypt { private $crypt_key; // 建構函式public function __construct($crypt_key) { $this -> crypt_key = $crypt_key;} public function php_encrypt($txt) { srand((double)microtime() * 1000000); $encrypt_key = md5(rand(0,32000)); $ctr = 0; $
Time of Update: 2016-07-25
class database { private $hostname; private $user; private $pass; private $dbname; private $linkflag; private $charset; function __construct() { $this->hostname="localhost";
Time of Update: 2016-07-25
在做web開發的時候經常會需要用到對行動裝置的頁面匹配,當然可以直接把網站做成響應式的,但如果不想這麼做的話,可以使用PHP對裝置類型進行判斷, 然後顯示相應的介面和內容。今天分享一種使用 PHP 判斷裝置是否是手機/平板的方法,方法來源於WordPress(wp-includes/vars.php:125),適用於大部分類型的手機/平板判 斷: /** * Test if the current browser runs on a mobile device (smart phone,
Time of Update: 2016-07-25
使用前請引入PHPExcel庫 /** * excel 寫入,基於PHPExcel庫 * @param array $data * @param $file * @return bool * @throws PHPExcel_Exception * */function excel_insert(array $data,$file){// $data = [// '庫房'=>[// ['庫房編號','庫房名詞',1],//
Time of Update: 2016-07-25
//PHP刪除目錄和目錄內所有的下級目錄、檔案代碼 function delDir( $dirName='' ){ if ( $handle = opendir( "$dirName" ) ) { while ( false !== ( $item = readdir( $handle ) ) ) { if ( $item != "." && $item != ".." ) {
Time of Update: 2016-07-25
function unzip($location,$newLocation){ if(exec("unzip $location",$arr)){ mkdir($newLocation); for($i = 1;$i $file = trim(preg_replace("~inflating: ~","",$arr[$i])); copy($location.'/'.$file,$newLocation.'/'.$file); unlink($location.'/'.$file); }
Time of Update: 2016-07-25
header('content-type:text/html;charset=gbk'); set_time_limit(0);//防止逾時 /** * * php目錄掃描監控增強版 * * @version 1.0 * 下面幾個變數使用前需要手動設定 * **/ /*===================== 程式配置 =====================*/ $pass="test";//設定密碼 $jkdir=".";
Time of Update: 2016-07-25
// 引用class檔案夾對應的類require_once('class/BCGFontFile.php');require_once('class/BCGColor.php');require_once('class/BCGDrawing.php'); // 條碼的編碼格式require_once('class/BCGcode39.barcode.php'); // 載入字型大小$font = new BCGFontFile('./class/font/Arial.ttf', 18);
Time of Update: 2016-07-25
使用下面的 PHP 程式碼片段可以在一個目錄中列出所有檔案和檔案夾 function list_files($dir){ if(is_dir($dir)) { if($handle = opendir($dir)) { while(($file = readdir($handle)) !== false) { if($file != "." && $file !=
Time of Update: 2016-07-25
$curl=curl_init();curl_setopt($curl, CURLOPT_URL, "http://www.baidu.com/");curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:20.0) Gecko/20100101 Firefox/20.0');curl_setopt($curl, CURLOPT_REFERER, 'http://www.guahao.com/
Time of Update: 2016-07-22
一、模板中的注釋每一個Smarty模板檔案,都是通過Web前台語言(xhtml,css和javascript等)結合Smarty引擎的文法開發的。 用到的web前台開發的語言和原來的完全一樣,注釋也沒有變化 Smarty注釋文法是'左結束符變數值*'和'*右結束符變數值',在這兩個定界符之間的內容都是注釋內容,可以包含一行或多行,並且使用者瀏覽網頁查看原代碼時不會看到注釋,它只是模板內在的注釋,以下是注釋小例子。 $smarty->left_lelimiter = '