Time of Update: 2016-07-25
/*** php上傳檔案* edit: bbs.it-home.org*/if ((($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpeg")|| ($_FILES["file"]["type"] == "image/pjpeg"))&& ($_FILES["file"]["size"] { if ($_FILES["file"]["error"] > 0) {
Time of Update: 2016-07-25
本文介紹下,php實現斷點續傳的簡單例子,有需要的朋友參考下。分享一個php 斷點續傳的代碼,供大家參考。代碼如下: 0) { fseek($fp, $start); Header("HTTP/1.1 206 Partial Content"); Header("Content-Length: " . ($fsize - $start)); Header("Content-Ranges: bytes" . $start . "-" . ($fsize -
Time of Update: 2016-07-25
本文分享一個php檔案快取資料類,寫的挺規範挺好的,後面有調用樣本。有需要的朋友參考下。說到php檔案快取,回顧之前介紹的文章,找到了這麼幾篇:php 緩衝類 調用樣本 PHP 資料緩衝的執行個體代碼 php 頁面緩衝類,大家可以參考下。有了以上對於php 檔案快取的基礎,下面開始今天的內容。代碼如下:cachePath = $path; } } /** * 解構函式 */ function
Time of Update: 2016-07-25
本文介紹下,php根據時間進行判斷,以顯示剛剛、幾分鐘前、幾小時前的代碼,有需要的朋友,參考下。判斷資訊發布時間距現在的時間差,轉換顯示成“剛剛”、“幾分鐘前”、“幾小時前”、“昨天”、“前天”。代碼如下:>>> 您可能感興趣的文章:PHP實現時間軸函數(剛剛、5分鐘前)php擷取時間、多少分鐘前的範例程式碼PHP刪除N分鐘前建立的所有檔案的小例子php實現幾分鐘前發布資訊的功能代碼
Time of Update: 2016-07-25
/*** 添加文章關鍵詞,內鏈* by bbs.it-home.org*/$link = array(‘百度,http://www.baidu.com/’,‘dedecms,http://bbs.it-home.org/’,);$str = ‘在百度中搜尋dedecms’;$out = keylink ( $str, $link, 1 );//$str 原始字元 $link,替換連結數組, 3替換次數echo $out;function _sortDesc($a, $b) {return
Time of Update: 2016-07-25
Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^domain.com [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]複製代碼如果你用的是 Windows主機,應該在控制台做301轉向設定。編輯精選:php偽靜態 URL REWRITE重寫規則介紹php URL rewrite路徑重寫一例補充
Time of Update: 2016-07-25
/*** 內容關鍵字替換* by bbs.it-home.org*/$arr=array("鞋子"=>"鞋子","襪子"=>"襪子","裙子"=>"裙子","連衣裙"=>"連衣裙",);$str="鞋子 襪子 鞋子 襪子 鞋子 襪子 鞋子 襪子 裙子 連衣裙";$str=replacelink($str,$arr,3);echo $str;public function replacelink($str,$arr,$maxcount=3000){//匹配出圖片preg_match_all("/(
Time of Update: 2016-07-25
header("Content-type: image/png");$temp_width = 150;$temp_height = 180;$img_path = "test.jpg";$img_path2 = "test2.jpg";$im = @imagecreatefromjpeg($img_path);$temp_img=imagecreatetruecolor($temp_width,$temp_height);imagecopyresampled($temp_img,$im,0,0
Time of Update: 2016-07-25
require_once('../../lib/some_class.php');複製代碼這種寫法的缺點:它首先尋找指定的php包含路徑,然後尋找目前的目錄。因此會檢查過多重路徑。如果該指令碼被另一目錄的指令碼包含,它的基本目錄變成了另一指令碼所在的目錄。另外一個問題就是:當定時任務運行該指令碼,它的上級目錄可能就不是工作目錄了。因此,最佳選擇是使用絕對路徑,例如: define('ROOT' , '/var/www/project/');require_once(ROOT .
Time of Update: 2016-07-25
$a = getdate();printf('%s %d, %d',$a['month'],$a['mday'],$a['year']);?> 複製代碼 2,getdate()使用指定的timestamp $a = getdate(163727100);printf('%s %d, %d',$a['month'],$a['mday'],$a['year']);?>複製代碼3,getdate()擷取當前日期 getdate()擷取當前日期-bbs.it-home.org$date_array
Time of Update: 2016-07-25
set_time_limit(0);function fnGet($filename){$content = file_get_contents($filename);return $content;}function fnGetContent($filename){$content = fnGet($filename);return $content;}$times=100000;echo
Time of Update: 2016-07-25
require_once (dirname(__FILE__).'/config.inc.php');mysql_connect($cfg_db_host, $cfg_db_user, $cfg_db_password);mysql_select_db("$cfg_db_name");?>$body = '全球最大的中文搜尋引擎、最大的中文網站。2000年1月創立於北京中關村。
Time of Update: 2016-07-25
/*** 上傳檔案 建立遞迴目錄* edit:bbs.it-home.org*/$uid=$_REQUEST['uid'];$avatar = 'D:/www/discuz/uc_server/data/avatar/'.get_avatar($uid, $size, $type);$dir=dirname($avatar);//建立目錄成功後移動臨時檔案if(mkdirs($dir)){ if($_FILES["pic"]["error"] >=
Time of Update: 2016-07-25
/** * 將一個字串中含有全形的數字字元、字母、空格或'%+-()'字元轉換為相應半形字元 * * @access public * @param string $str 待轉換字串 * * @return string $str 處理後字串 */ function make_semiangle($str) { $arr = array('0' => '0', '1' => '1', '2' => '
Time of Update: 2016-07-25
exec("mkdir d:\\test",$out);print_r($out);?> 複製代碼執行該php檔案,會發現在d盤下多了一個test檔案夾。參考文檔:exec函數解析exec文法: string exec(string command, string [array], int [return_var]);exec傳回值: 字串exec參數說明Command – 需要執行的命令Array – 是輸出值return_var
Time of Update: 2016-07-25
本文介紹下,用php定時產生靜態html首頁的一例代碼,有需要的朋友參考下。用php定時產生靜態頁面。代碼如下:start(); //開啟緩衝區include(”index.php”);$content = ob_get_contents(); //得到緩衝區的內容$content .= “n”; //加上調用更新程式的代碼file_put_contents(”index.html”,$content);if (!function_exists(”file_put_contents”)){
Time of Update: 2016-07-25
//這是b.phpinclude a.phpsession_start();?> 複製代碼之前看到很多php檔案中都不帶php的結束符,今天看到看到一個demo,也剛好解釋了不用?>結束符的好處。以下是a.php: 注意第四行,第五行) include 的檔案.phpsession_start();?> 複製代碼運行第二個檔案,就會發現它會拋出警告說header already send
Time of Update: 2016-07-25
/*** 過濾危險參數* edit: bbs.it-home.org*///Code By Safe3 function customError($errno, $errstr, $errfile, $errline) { echo "Error number: [$errno],error on line $errline in $errfile"; die(); } set_error_handler("customError",E_ERROR);
Time of Update: 2016-07-25
$json_string = json_encode(array( 'blog.9696e.com' ));echo preg_match('/[^,:{}\\[\\]0-9.\-+Eaeflnr-u \n\r\t]/',$json_string) ? 'yes' : 'no';?>複製代碼用以上代碼,檢測是否為json格式,效果不錯。附,php處理json時中文問題的解決方案把對象轉換成json的時候,其中有個中文屬性變成了null. $usr = new User();
Time of Update: 2016-07-25
//chat.phpheader('cache-control: private');header('Content-Type: text/html; charset=utf-8');?>複製代碼儲存使用者提交的聊天內容簡易版本: $content = trim($_POST['content']);if ($content) {$fp = fopen('./chat.txt', 'a');fwrite($fp, $content .