這篇文章主要為大家展示了“PHP有哪些常用函數(shù)”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“PHP有哪些常用函數(shù)”這篇文章吧。
成都網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)!專注于網(wǎng)頁(yè)設(shè)計(jì)、成都網(wǎng)站建設(shè)、微信開(kāi)發(fā)、成都小程序開(kāi)發(fā)、集團(tuán)成都定制網(wǎng)站等服務(wù)項(xiàng)目。核心團(tuán)隊(duì)均擁有互聯(lián)網(wǎng)行業(yè)多年經(jīng)驗(yàn),服務(wù)眾多知名企業(yè)客戶;涵蓋的客戶類型包括:成都水處理設(shè)備等眾多領(lǐng)域,積累了大量豐富的經(jīng)驗(yàn),同時(shí)也獲得了客戶的一致贊美!
PHP常用函數(shù)1.產(chǎn)生隨機(jī)字符串函數(shù)
function random($length) {
$hash = @#@#;
$chars = @#abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz@#;
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}
PHP常用函數(shù)2.截取一定長(zhǎng)度的字符串
注:該函數(shù)對(duì)gb2312使用有效
function wordscut($string, $length ,$sss=0) { if(strlen($string) > $length) { if($sss){ $length=$length - 3; $addstr=@# ...@#; } for($i = 0; $i < $length; $i++) { if(ord($string[$i]) > 127) { $wordscut .= $string[$i].$string[$i + 1]; $i++; } else { $wordscut .= $string[$i]; } } return $wordscut.$addstr; } return $string; }
PHP常用函數(shù)3.取得客戶端ip地址
function getip(){
if (getenv("http_client_ip")
&& strcasecmp(getenv("http_client_ip"), "unknown"))$ip = getenv("http_client_ip");
else if (getenv("http_x_forwarded_for")
&& strcasecmp(getenv("http_x_forwarded_for"), "unknown"))$ip = getenv("http_x_forwarded_for");
else if (getenv("remote_addr")
&& strcasecmp(getenv("remote_addr"), "unknown"))$ip = getenv("remote_addr");
else if (isset($_server[@#remote_addr@#])
&& $_server[@#remote_addr@#]
&& strcasecmp($_server[@#remote_addr@#], "unknown"))$ip = $_server[@#remote_addr@#];
else
$ip = "unknown";
return($ip);
}
PHP常用函數(shù)4.創(chuàng)建相應(yīng)的文件夾
function createdir($dir=@#@#) { if (!is_dir($dir)) { $temp = explode(@#/@#,$dir); $cur_dir = @#@#; for($i=0;$i以上是“PHP有哪些常用函數(shù)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
本文名稱:PHP有哪些常用函數(shù)
瀏覽路徑:http://weahome.cn/article/gisipj.html