Time of Update: 2016-07-25
$a=array("a"=>"Dog","b"=>"Cat");if (array_key_exists("a",$a)){echo "Key exists!";}else{echo "Key does not exist!";}?>複製代碼輸出:Key exists!例2: $a=array("a"=>"Dog","b"=>"Cat");if (array_key_exists("c",$a)){echo "Key exists!";}else{echo "Key does not
Time of Update: 2016-07-25
介紹:將資料庫使用者名稱、密碼等儲存在設定檔config.php中,然後在需要的地方使用include或require包含進來,並在函數裡用global關鍵字將存放資料庫名,密碼等的變數全域化,便可以在檔案裡的函數中使用了。介紹:將資料庫使用者名稱、密碼等儲存在設定檔config.php中,然後在需要的地方使用include或require包含進來,並在函數裡用global關鍵字將存放資料庫名,密碼等的變數全域化,便可以在檔案裡的函數中使用了。1、設定檔-config.php:2、資料庫操作類(
Time of Update: 2016-07-25
// 迴圈建立目錄function mk_dir($dir, $mode = 0755){if (is_dir($dir) || @mkdir($dir,$mode)) return true;if (!mk_dir(dirname($dir),$mode)) return false;return @mkdir($dir,$mode);}複製代碼方法2: $filepath = "test/upload/2010/image.gif";createDir(dirname($filepath))
Time of Update: 2016-07-25
/*** Author : GuoWangYunYan* QQ : 279861795* Date : 2011-6-23* link:www.jbuxe.com*///設定編碼header('Content-type: text/html; charset=utf-8');//比較變態的用了個五維數組$a = array( 'AAAAAA' => array( 'aaaaaa' => array( '111111',
Time of Update: 2016-07-25
/* 判斷常量是否存在*/if (defined('MYCONSTANT')) {echo MYCONSTANT;}//判斷變數是否存在if (isset($myvar)) {echo "存在變數$myvar.";}//判斷函數是否存在if (function_exists('imap_open')) {echo "存在函數imag_open\n";} else {echo "函數imag_open不存在\n";}?>複製代碼
Time of Update: 2016-07-25
php在建立數組時不需要指定其大小。由於php是一種鬆散類型的語言,所以甚至不需要在使用數組前先行聲明。雖然沒有嚴格的限制,但php還是提供了正式與非正式的數組聲明方法。php在建立數組時不需要指定其大小。由於php是一種鬆散類型的語言,所以甚至不需要在使用數組前先行聲明。雖然沒有嚴格的限制,但php還是提供了正式與非正式的數組聲明方法。本文將為大家介紹兩種建立php數組的方法,供大家學習參考。方法1:直接使用賦值的方法建立數組下面我們建立一個包含指令碼學堂名稱的數組:php中數組的下組也是從0
Time of Update: 2016-07-25
在php中,常量(constant)是指在程式執行中無法修改的值。當處理絕對不需要修改的值時,可以考慮將其設定為常量。在php中,常量(constant)是指在程式執行中無法修改的值。當處理絕對不需要修改的值時,可以考慮將其設定為常量。例如:一英裡相當於多少英長(5280),可以把這樣的數值設定為常量。常量一經定義,在程式中任何地方,便不可以修改了。在php中,我們使用define()函數來定義常量。define()函數通過給一個變數名賦值來定義一個常量,其形式如下:boolean
Time of Update: 2016-07-25
/** desc:數組合并 link:bbs.it-home.org date:2013/2/22*/$a = array( 'a' => 1, 'b' => 2 );$b = array( 'b' => 3, 'd' => 4 );//數組合并$array_merge = array_merge( $a, $b );echo '';print_r( $array_merge );//數組遞迴合并$array_merge_recursive = array_merge_recursive(
Time of Update: 2016-07-25
[Date]; Defines the default timezone used by the date functions;date.timezone =複製代碼預設是關閉的,只需把注釋去掉,改為即可 [Date]; Defines the default timezone used by the date functionsdate.timezone =
Time of Update: 2016-07-25
/** php資料流應用 date:2013/2/19*/$count = 5; start: if($count echo "Put Password: "; $handle = fopen ("php://stdin","r"); $line = fgets($handle); if(trim($line) != '123456'){ $count--; if(!$count) goto error; goto start; } goto success; error: echo
Time of Update: 2016-07-25
/*** 遞迴 無限級分類 返回數組* link:bbs.it-home.org* date:2013/2/21*/$conn = mysql_connect('localhost','root','123456');mysql_select_db('test');mysql_query("set names 'utf8'");function getCate($pid = 0){$sql = "select * from cate where pid=".$pid;$res =
Time of Update: 2016-07-25
php中的數組有一維數組、二維數組和多維陣列。一維數組的遍曆很簡單,一個for迴圈即可實現。對於二維數組、多維陣列的遍曆,則需要下點功夫了。這裡為大家舉一個多維陣列遞迴遍曆的例子,供大家參考。運行結果:Array( [1] => Array ( [0] => 11 [1] => 12 [2] => 13 [14] => Array ( [0] => 141 [1]
Time of Update: 2016-07-25
/** desc:檢網路地址格式是否有效 link:bbs.it-home.org date:2013/2/24*/function checkUrl($weburl) { return !ereg("^http(s)*://[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*$", $weburl); } ?>複製代碼2、判斷http 地址是否有效 /** desc:檢測http 地址是否有效 link:bbs.it-home.org date:2013
Time of Update: 2016-07-25
$array = array('abcd','abcde','bcde','cdef','defg','defgh');$str = '~'.implode('~',$array).'~';$word = $_GET['word']; //url = xxx.php?word=apreg_match_all("/~({$word}(?:[^~]*))/i",$str,$matches);var_dump($matches[1]);//輸出//array(2) { [0]=> string(4)
Time of Update: 2016-07-25
echo'hello';echo'world!';?> 複製代碼output:hellloworld!例2: echo'hello\n';//unix系統使用\n;windows系統下\r\necho'world!';?> 複製代碼output:helloworld!通過以上兩個例子,相信你已經理解php中\n、\r\n及的應用場合了吧。您可能感興趣的文章:php fwrite寫入txt檔案 \r\n不能換行的解決方案
Time of Update: 2016-07-25
/** desc:設定檔 link:bbs.it-home.org date:2013/2/24*/$name="admin";//kkkk$bb='234';$db=4561321;$kkk="admin";?>複製代碼函數定義:設定檔資料值擷取:function getconfig($file, $ini, $type="string")設定檔資料項目更新:function updateconfig($file, $ini, $value,$type="string")調用方式:
Time of Update: 2016-07-25
/** desc:採集網頁中的郵箱的代碼 link:bbs.it-home.org date:2013/2/24*/$url='http://bbs.it-home.org'; //這個網頁裡絕對含有郵件地址。$content=file_get_contents($url);//echo $content;function getEmail($str) {//$pattern = "/([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+
Time of Update: 2016-07-25
/** desc:正則過濾html標籤、空格、分行符號等 link:bbs.it-home.org date:2013/2/23*/$str=preg_replace("/\s+/", " ", $str); //過濾多餘斷行符號$str=preg_replace("/$str=preg_replace("//si","",$str); //注釋$str=preg_replace("//si","",$str); //過濾DOCTYPE$str=preg_replace("//si",""
Time of Update: 2016-07-25
$s = "this is a string";$i = 9;$arr = array(2,4,6);is_string($s); //返回TRUE,表示$s是一個字串變數is_string($i); //返回FALSE,表示$i不是一個字串變數is_array($arr); //返回TRUE,表示$arr是一個數組is_array($s); //返回FALSE,表示$s不是一個數組$str = "this is a string";$int = 9;$bool = FALSE;echo "\$
Time of Update: 2016-07-25
echo number_format("1000000"); echo number_format("1000000",2); echo number_format("1000000",2,",","."); ?>複製代碼輸出: 1,000,000 1,000,000.00 1.000.000,00有意思的number_format