根據utf8編碼規律截取字串的函數(utf8版的sub_str)

/** 功能: 作用跟substr一樣,除了它不會造成亂碼* 參數:* 返回:*/function utf8_substr( $str , $start , $length=null ){// 先正常截取一遍.$res = substr( $str , $start , $length );$strlen = strlen( $str );/* 接著判斷頭尾各6位元組是否完整(不殘缺) */// 如果參數start是正數if ( $start >= 0 ){//

php eval函數用法及相關技巧

$string = '杯子';$name = '咖啡';$str = '這個 $string 中裝有 $name.';echo $str;eval( "\$str = \"$str\";" );echo $str;?>複製代碼本例的傳回值為這個 $string 中裝有 $name.這個 杯子 中裝有

php調用外部shell的方法總結

system("/usr/local/bin/webalizer/webalizer");?>複製代碼exec()原型:string exec (string command [, string array [, int return_var]])exec() 函數與system()類似,也執行給定的命令,但不輸出結果,而是返回結果的最後一行。雖然它只返回命令結果的最後一行,但用第二個參數array可以

php的eval函數用法小結

$string = "beautiful";$time = "winter";$str = 'This is a $string $time morning!';echo $str. "";eval("$str = "$str";");echo $str;?>  複製代碼輸出:This is a $string $time morning!This is a beautiful winter morning!eval() 函數在CodeIgniter架構裡也有用到。在

使用php判斷檔案是否存在、是否可讀、目錄是否存在

$file = 'bbs.it-home.org.php';if (is_readable($file) == false) {die('檔案不存在或者無法讀取');} else {echo '存在';}?>複製代碼is_readable() 函數判斷指定檔案名稱是否可讀。指定的檔案或目錄存在並且可讀,則返回 TRUE例2: $filename = 'bbs.it-home.org.php';if (file_exists($filename)) {echo "The file

php添加關聯連結的代碼

/*** php關聯連結*/header("Content-Type:text/html;charset=utf-8"); //設定編碼$linkdatas=array(array('前端開發', 'http://http://bbs.it-home.org'),array('前端設計', 'http://bbs.it-home.org'),array('web前端', 'http://bbs.it-home.org'),array('前端部落格',

php中的daddslashes()和saddslashes()的區別

//----saddslashesfunction daddslashes($string, $force = 0, $strip = FALSE) {//字串或數組 是否強制 是否去除//如果魔術引用未開啟 或 $force不為0if(!MAGIC_QUOTES_GPC || $force) {if(is_array($string)) { //如果其為一個數組則迴圈執行此函數foreach($string as $key => $val) {$string[$key] =

一個測試php程式已耗用時間的類

class runTime {private $starTime;//開始時間private $stopTime;//結束時間private function getMicTime(){$mictime=microtime();//擷取時間戳記和微秒數list($usec,$sec)=explode(" ",$mictime);//把微秒數分割成數組並轉換成變數處理return (float)$usec+(float)$sec;//把轉換後的資料強制用浮點點來處理}public

php實現的無極分類(遞迴)的代碼

$conn=mysql_connect("localhost","root","myoa888");mysql_select_db("lost63",$conn) or die("select db error");$sql[]="Create TABLE `lost63`.`dd_book_class` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`classname` VARCHAR( 50 ) NOT NULL ,`classid`

一個計算程式已耗用時間的php類

/*** 計算程式已耗用時間* filename: js_runtime.php*/class Timer {private $StartTime = 0;//程式運行開始時間private $StopTime = 0;//程式運行結束時間private $TimeSpent = 0;//程式運行花費時間function start(){//程式運行開始$this->StartTime = microtime();}function stop(){//程式運行結束$this->StopTime

php冒泡排序與快速排序的例子

function bubbingSort(array $array){for($i=0, $len=count($array)-1; $i{for($j=$len; $j>$i; --$j){if($array[$j] {$temp = $array[$j];$array[$j] = $array[$j-1];$array[$j-1] = $temp;}}}return $array;}print

php寫的遞迴列出所有檔案和目錄的函數

/*簡單的目錄遞迴函式*/function tree($directory){$mydir=dir($directory);echo "";while($file=$mydir->read()){if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!="..")){echo "$file";tree("$directory/$file");}else{echo "$file";}}echo "";$mydir->close();}

php取得檔案的尾碼名的方法

$pic = 'abc.3434.342.12123.123.exe';$pics = explode('.' , $pic);/*得到數組總數,然後取最後一個*/echo $num = count($pics);echo ''.$pics[$num-1];/*遍曆數組,取得最後一個元素*/foreach ($pics as $value) //2{$a = $value;}echo $a.'';/*直接輸出數組最後一個元素*/echo end($pics);echo

php隨機輸出名人名言的函數

function random_str () {$poems="人生的價值,並不是用時間,而是用深度去衡量的。-- 列夫·托爾斯泰三人行,必有我師焉。擇其善者而從之,其不善者而改之。——孔子人生不是一種享樂,而是一樁十分沉重的工作。-- 列夫·托爾斯泰成為卓越的代名詞,很多人並不需要傑出素質的環境。——Steve Jobs活著就是為了改變世界,難道還有其他原因嗎?——Steve JobsFollow yourself.追隨你的內心。——Steve

php中display_errors與log_errors的區別

# vim /etc/php.inidisplay_errors = Offlog_errors = Onerror_log = /var/log/php-error.log複製代碼另外也可以設定error_log = syslog,使這些錯誤資訊記錄到作業系統的日誌裡。display_errors = Off //display中文意思是顯示所以display_error=off的意思就是不顯示錯誤了!error_reporting

php與mysql實現的無限級分類|樹型顯示分類的關係

//$count為分類等級sort_list($str,$fatherid,$count){$rs = $this->sql->re_datas("select * from sort where father_id = fatherid");$num = $this->sql->sql_numrows();$i=0;$n = 1;while(isset($rs[$i])){$name = "";for($n = 1 ; $n {$name.="│

php用遞迴方法實現無限級分類的代碼

$dbhost = "localhost"; // 資料庫主機名稱$dbuser = "root"; // 資料庫使用者名稱$dbpd = "123456"; // 資料庫密碼$dbname = "test"; // 資料庫名mysql_connect($dbhost,$dbuser,$dbpd); //串連主機mysql_select_db($dbname); //選擇資料庫mysql_query("SET NAMES

對ecshop中的無限級分類的分析

function cat_options($spec_cat_id, $arr){static $cat_options = array();if (isset($cat_options[$spec_cat_id])){return

php實現標籤雲的一段代碼

/*** WNiaoBlog Tag Template ShowTag** @package WNiaoBlog** @subpackage Tag*///Connect the database//include('../include/config.php');/*** CountTag() - Statistics labels appear the number,and the data to be stored in the two array** GetTag() - Access

php模板函數的正則實現代碼

function template($tpl = 'index',$dir = 'hello'){if(!file_exists($pd = TPL_PATH.$dir.'/'))@mkdir($pd,0777) or die("$pd目錄建立失敗");//如cache/tpl/hello/if(!file_exists($td = TPL.$dir.'/'))@mkdir($td,0777) or die("$td目錄建立失敗");//如data/tpl/hello/$t2p =

總頁數: 5203 1 .... 2142 2143 2144 2145 2146 .... 5203 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.