Time of Update: 2016-07-25
本文介紹下,用php擷取本周、本月第一天與最後天時間戳記的代碼,有需要的朋友作個參考。用php擷取本周、本月第一天與最後天時間戳記。1,擷取今天的時間範圍:2,擷取本周第一天/最後一天的時間戳記 $nowMonthDay){ $lastday = $lastday - $nowMonthDay; $lastMonth = $month + 1; $time_2 = strtotime($year."-".$lastMonth."-".$lastday);}else{ $time_2 =
Time of Update: 2016-07-25
分享下php調用使用者自訂函數的方法,有簡單有複雜,適合初學php自訂函數的朋友參考。在php中調有自訂函數,經常會用到call_user_func函數、call_user_func_array函數、call_user_func函數。1,call_user_func函數類似於一種特別的調用函數的方法,使用方法如下:調用類內部的方法比較奇怪,用到了array,省去了new操作,在一定程度上節省了資源:2,call_user_func_array函數和call_user_func很相似,只不過是換了
Time of Update: 2016-07-25
本文介紹一段php 標籤雲效果的實現代碼,原理很簡單,實現的方法略顯質樸,呵呵。有興趣研究php 雲標籤的朋友作個參考吧。分享一段php 標籤雲的實現代碼。代碼: ".$EachTag."(".$EachCount.")"." "; $i++; } } function GetTag(){ $QuerySet = mysql_query("select * from article"); while($Row = mysql_fetch_array($QuerySet)){ $Tag =
Time of Update: 2016-07-25
如何計算兩個檔案之間的相對路徑呢?用php實現是很簡單的,這裡分享一段代碼,可以計算兩個檔案的相對路徑,有需要的朋友不妨參考下。計算出兩個檔案的相對路徑。例如,有檔案如下:$a="/a/b/c/d/e.php"; $b="/a/b/12/34/c.php"。那麼如何計算出B相對於A的相對路徑呢?代碼: $counta) { while ($countb > $counta) { $path .= "../"; $countb --;
Time of Update: 2016-07-25
echo '本周第一天(星期日為一周開始):'.date('Y-m-d', time()-86400*date('w')).'';echo '本周第一天(星期一為一周開始):'.date('Y-m-d', time()-86400*date('w')+(date('w')>0?86400:-6*86400)).'';echo '本月第一天:'.date('Y-m-d', mktime(0,0,0,date('n'),1,date('Y'))).'';echo '本月最後一天:'.date('Y-
Time of Update: 2016-07-25
分享一個截取指定長度字串的函數,可以對字串指定要截取的長度,並可以設定超出部分的顯示內容,很不錯,值得借鑒與學習。根據中文裁減字串,截取指定長度的字串內容。代碼如下:'),array($pre . '&'. $end, $pre . '"' . $end, $pre . '' . $end), $string); $strcut = ''; if (strtolower(CHARSET) == 'utf-8'){ $n = $tn =$noc = 0; while
Time of Update: 2016-07-25
本文介紹下,在php編程中,關閉已開啟的檔案的方法,有需要的朋友參考下。在php中,當開啟檔案進行相關操作以後,需要及時的對檔案控制代碼進行關閉,以避免較長時間的資源佔用。php 關閉檔案在php編程中,當用完一個檔案之後,一定要及時的關閉,這是一個良好的習慣。php
Time of Update: 2016-07-25
本文分享下,一段可類比撲克牌玩法的php代碼,有需要的朋友參考下。php 撲克牌代碼,如下:cut();* www: jbxue.com*/class cards{/**** Declare our deck variable **/private $deck;/**** Constructor.. duh!**/function __construct(){ /*** set the deck array variable ***/ $this->deck=$this->setDeck()
Time of Update: 2016-07-25
本文介紹下,php中用於中文字元截取的一個函數,有需要的朋友參考下。分享一個自己一直在用的PHP中文字元截取函數,很不錯,有用到的朋友拿去吧。代碼:<?php/*** @ 中文字元截取* @ site:bbs.it-home.org*/function str_cut($string, $length, $dot = ”) {if(strlen($string) <= $length) { return $string;}$strcut = ”;for($i = 0; $i
Time of Update: 2016-07-25
本文收集了一些php中有關stream資料流的函數集,有需要的朋友,可以參考下。php stream函數集,如下:
Time of Update: 2016-07-25
echo $_SERVER['SCRIPT_FILENAME'].''; echo __FILE__;複製代碼執行a.php 得到: require 'a.php';複製代碼執行b.php,結果為: E:/var/www/b.php ($_SERVER['SCRIPT_FILENAME'])E:\wamp\www\Text\a.php (__FILE__)由此,我們得出二者的區別:$_SERVER['SCRIPT_FILENAME'] 當前執行程式的絕對路徑及檔案名稱__FILE__
Time of Update: 2016-07-25
本文介紹下,用php擷取網頁內容的四種方法,包括xmlhttp方法、file_get_contents方法、fopen方法、curl方法。有需要的朋友參考下。1,使用xmlhttp對象,類似asp中的ActiveXObject對象。代碼:open("GET","http://localhost/xxx.php?id=2",false); $xhr->send(); echo
Time of Update: 2016-07-25
function createTagCloud($tags) { //I pass through an array of tags $i=0; foreach($tags as $tag) { $id = $tag['id']; //the tag id, passed through $name = $tag['tag']; //the tag name, also passed through in
Time of Update: 2016-07-25
if (isset($_REQUEST['GLOBALS']) OR isset($_FILES['GLOBALS'])) { exit('Request tainting attempted.');}複製代碼register_globals 是php中的一個控制選項,可以設定成off或者on ,預設為off,決定是否將 EGPCS(Environment,GET,POST,Cookie,Server)變數註冊為全域變數。如果 register_globals開啟的話,
Time of Update: 2016-07-25
本文介紹下,用php實現的查詢百度收錄、Google收錄情況的一段代碼,有需要的朋友參考下。用php來查詢百度或google的收錄情況,其實並不複雜,只需要file下遠程檔案,然後分析相關資料即可。以下是收錄查詢核心代碼,getdetail函數也可以這樣寫,用正則去匹配: $wordf = preg_quote($wordf);$wordb = preg_quote($wordb);$pagecontent = @preg_replace("/\s*$wordf(.+?)$wordb\s*/e"
Time of Update: 2016-07-25
本文介紹下,用php實現的一個可以多線程下載遠程多個檔案的函數,有需要的朋友參考下。以下代碼,實現:多線程下載遠程多個檔案,如下: $v) {if (!empty($v) && preg_match("~^http~i", $v)) {$nurl[$k] = trim(str_replace(' ', "%20", $v));$curl[$k] = curl_init($nurl[$k]);curl_setopt($curl[$k], CURLOPT_IPRESOLVE,
Time of Update: 2016-07-25
變數 empty is_null isset$a=”” true false true$a=null true true falsevar $a true true false$a=array() true false true$a=false true false
Time of Update: 2016-07-25
本文介紹下,在php中用於處理基準時間的一段代碼,有需要的朋友,參考下吧。Here is a little example of how to benchmark or time something with php這裡有一段php代碼,教大家如何去處理基準時間。代碼如下:';}// the end time$time_end = getmicrotime();// subtract the start time from the end time to get the time
Time of Update: 2016-07-25
Typecho_Widget::widget('Widget_Metas_Tag_Cloud')->to($tags); ?>have()): ?>next()): ?> ,, )" href="permalink();?>"> name(); ?> 複製代碼若是單頁面添加的標籤雲,則在page.php頁面把content(); ?>替換為以下代碼: slug=="tags"): ?>to($tags); ?>have()): ?> next()): ?> ,,)"
Time of Update: 2016-07-25
與大家一起探討,在php編程中,逗號與點號區別的那點事,有需要的朋友,不妨參考下哦。在php中,逗號要比點號快,究竟原因有幾何呢?本文將為大家一一說來。先看代碼:通過執行個體瞭解下php中逗號與點號的區別。代碼:echo '1+5=' . 1+5;看看上面的.輸出的結果是6..而不是1+5=6.有些神奇吧?一個神奇的例子: echo "1+5=" . 5+1;