/** * json_encode的替代函數 * Edit bbs.it-home.org*/ function jsonEncode($var) { if (function_exists('json_encode')) { return json_encode($var); } else { switch (gettype($var)) { case
/*** php偽靜態* bbs.it-home.org*/$conn=mysql_connect("localhost","root","root")or dir("串連失敗");mysql_select_db("tb_demo",$conn);$sql="select * from news";$res=mysql_query($sql);header("content-type:text/html;charset=utf-8");echo "新聞列表";echo "添加新聞";echo "
//將url轉換成靜態url function url_rewrite($file,$params = array (),$html = "",$rewrite = true) { if ($rewrite) { //開發階段是不要rewrite,所在開發的時候,把$rewrite = false $url = ($file == 'index') ? '' : '/' . $file;
複製代碼當register_globals=Off時,下一個程式接收時應該用$_GET['user_name']和$_GET['user_pass']來接受傳遞過來的值。(註:當的method屬性為post的時候應該用$_POST['user_name']和$_POST['user_pass'])當register_globals=On時,下一個程式可以直接使用$user_name和$user_pass來接受值。也就是說,register_globals註冊為全域變數,所以當On時,傳遞過來的值
/** * 判斷上傳檔案類型 * Edit bbs.it-home.org*/ function file_type($filename) { $file = fopen($filename, "rb"); $bin = fread($file, 2); //唯讀2位元組 fclose($file); $strInfo = @unpack("C2chars", $bin);
介紹一個php stripslashes與addslashes應用的簡單例子,有需要的朋友,可以參考下。代碼如下:mystrip(&$v); } }else{ $data = stripslashes($data); } } //加上轉義 function addslashes_deep($value) { if (empty($value)) { return $value; //如為空白,直接返回; } else { return
SetCookie("Cookie", "cookievalue",time()+3600, "/forum", ".jbxue.com", 1);複製代碼1)、接收和處理CookiePHP對Cookie的接收和處理的支援非常好,是完全自動的,跟FORM變數的原則一樣,特別簡單。比如設定一個名為 MyCookier的Cookie,PHP會自動從WEB伺服器接收的HTTP頭裡把它分析出來,並形成一個與普通變數一樣的變數,名為$
//ini_set('memory_limit', '-1'); // 如果csv比較大的話,可以添加。 /* * $file : csv file * $csvDataArr : header of csv table, eg: arary('name','sex','age') or array(0,1,2) * $specialhtml : whether do you want to convert special characters
介紹一個php自訂函數,可以遍曆檔案夾下的檔案,目錄子目錄,讀取當前檔案下目錄和檔案等,共三個函數,暫不支援中文。供大家學習參考。代碼如下:array(),'file'=>array());$hd = opendir($path);while(($file = readdir($hd))!==false){if($file=="."||$file=="..") {continue;}if(is_dir($path."/".$file)){$arr['dir'][] = iconv('gbk','
header('Cache-control: private, must-revalidate'); //支援頁面回跳複製代碼2、使用session_cache_limiter方法。 session_cache_limiter('private, must-revalidate');
本文介紹下,php中的時間函數strtotime的用法,介紹一些具體的例子,協助大家的理解,有需要朋友不妨參考下。php中strtotime函數的功能:擷取某個日期的時間戳記,或擷取某個時間的時間戳記。strtotime 將任何英文文本的日期時間描述解析為Unix時間戳記[將系統時間轉化成unix時間戳記]。一,擷取指定日期的unix時間戳記 strtotime("2009-1-22")樣本: echo strtotime("2009-1-22")結果:1232553600說明:返回2009年1
phpmailer郵件發送測試-bbs.it-home.org請你輸入收信的郵箱地址:複製代碼2、發郵件程式 send.php /*** PHPMailer郵件發送* Edit bbs.it-home.org*/require("class.phpmailer.php");$mail = new PHPMailer();$mail->CharSet = "gb2312"; // 這裡指定字元集!如果是utf-8則將gb2312修改為utf-8$mail->Encoding = "base64";
本文分享幾個php程式員面試題,共有6個部分,適合正在找工作的phper朋友們,快來參考下吧。專題推薦:php面試題及答案面試題11、 用PHP列印出前一天的時間格式是2006-5-10 22:21:212、 echo(),print(),print_r()的區別3、 能夠使HTML和PHP分離開使用的模板4、 如何?PHP、JSP互動?5、 使用哪些工具進資料列版本設定?6、 6、如何?字串翻轉?7、 最佳化mysql資料庫的方法。8、 談談交易處理9、
// 購物車類/*使用說明:建構函式 cart 可以使用參數:cart($cartname = 'myCart', $session_id = '', $savetype = 'session', $cookietime = 86400, $cookiepath = '/', $cookiedomain = '')$cartname 是購物車的標識,可以指定,可以保證不重名,不會有相關衝突$session_id 是 session_id,預設是使用 cookie
{if $pageCount > 1} {foreach item=i from=$pagerList} {if $pageNum eq $i} {$i} {else} {$i}{/if} {/foreach} {if $pageNum eq 1} 上一頁{else} 上一頁{/if} {if $pageNum eq $pageCount } 下一頁{else} 下一頁{/if} {if $pageNum eq 1} 首頁{else} 首頁{/if}
echo strtotime ("now"), "\n";echo strtotime ("10 September 2000"), "\n";echo strtotime ("+1 day"), "\n";echo strtotime ("+1 week"), "\n";echo strtotime ("+1 week 2 days 4 hours 2 seconds"), "\n";echo strtotime ("next Thursday"), "\n";echo strtotime (
session_start(); $conn=mysql_connect("localhost","root","admin"); mysql_select_db("songyu"); //檢查數組元素出現次數 function check_count($array,$element) { $times=0; for($i=0;$i { if($element==$array[$i]) { $times++; } } return $times; }if(isset(
/** * Hex RGB顏色值互換 * Edit bbs.it-home.org * at 2013/5/11*/function HexToRGB($colour) {if ($colour [0] == '#') {$colour = substr ( $colour, 1 );}if (strlen ( $colour ) == 6) {list ( $r, $g, $b ) = array ($colour [0] . $colour [1],$colour [2] .
/** * php 購物車 * Edit bbs.it-home.org*///購物車session的產生代碼if(! $session && ! $scid) {/*session用來區別每一個購物車,相當於每個車的社會安全號碼;scid只用來標識一個購物車id號,可以看做是每個車的名字;當該購物車的id和session值兩者都不存在時,就產生一個新購物車*/$session =
class Shopcar{//商品列表public $productList=array();/**** @param unknown_type $product 傳進來的商品* @return true 購物車裡面沒有該商品*/public function checkProduct($product){for($i=0;$iproductList);$i++ ){if($this->productList[$i]['name']==$product['name'])return