All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP经典的给图片加水印程序_[PHP教程]
PHP技巧:得到一个字符串的最后一个字符_[PHP教程]
初学认识:javascript和Java是两个完全不同的语言_JavaScript技术_编程技术
ASP.NET2.0自动搜索文件组成导航系统_.net资料_编程技术
ASP2.0-FreeTextBox使用详解_[Asp.Net教程]
网站提高百度收录的五种方法_百度优化_seo学堂
PHP漏洞中的战争_[PHP教程]
.net(C#)开发小技巧漫谈之一_[Asp.Net教程]
如何在SQL Server中对行进行动态编号_[SQL Server教程]
Asp.net实例:实现图片上传_[Asp.Net教程]
Reading number is top 10 pictures
The real super beauty5
The Soviet union swimsuit exposure in the 70 year3
网上疯传的一篇小学作文《爸爸也治不了妈妈》
Female model behind the bitterness, often being overcharged2
Street street fighting
徐若瑄展示美丽胸围1
A man's favorite things3--ZhouWeiTong
Exquisite decoration is not paying too much4
Breasts woman big set 1
恶搞漫画1
Download software ranking
The Bermuda triangle1
传奇私服架设教程-chm
尖东毒玫瑰B
双旗镇刀客A
C++编程教程第三版
dreamweaver8中文版
Eclipse 4.2.2 For Win64
Proficient in JavaScript
天龙八部最新服务端
传奇私服架设教程
归海一刀 published in(发表于) 2014/2/17 7:34:44 Edit(编辑)
php技巧-几个比较实用的PHP函数_[PHP教程]

php技巧-几个比较实用的PHP函数_[PHP教程]

php技巧:几个比较实用的PHP函数_[PHP教程]
1. sys_getloadavg()

sys_getloadavt()可以获得系 统负载情况。该函数返回一个包含三个元素的数组,每个元素分别代表系统再过去的1、5和15分钟内的平均负载。

与其让服务器因负 载过高而宕掉,不如在系统负载很高时主动die掉一个脚本,sys_getloadavg()就是用来帮你实现这个功能的。 不过很遗憾,该函数在windows下无效。

2. pack()

Pack() 能将md5()返回的32位16进制字符串转换为16位的二进制字符串,可以节省存储空间。

3. cal_days_in_month()

cal_days_in_month()能够返回指定月份共有多少天。

4. _()

WordPress开发者经常能见到这个函数,还有 _e()。这两个函数功能相同,与gettext()函数结合使用,能实现网站的多语言化。具体可参见PHP手册的相关部分介绍。

5. get_browser()

在发送页面前先看看用户的浏览器都能做些什么是 不是挺好?get_browser()能获得用户的浏览器类型,以及浏览器支持的功能,不过首先你需要一个php_browscap.ini文件,用来给 函数做参考文件。

要注意,该函数对浏览器功能的判断是基于该类浏览器的一般特性的。例如,如果用户关闭了浏览器对 JavaScript的支持,函数无法得知这一点。但是在判断浏览器类型和OS平台方面,该函数还是很准确的。

6. debug_print_backtrace()

这是一个调试用的函数,能帮助你发现代码中的逻辑错误。要理 解这个函数,还是直接看个例子吧:

$a = 0;
function iterate() {
global $a;
if( $a < 10 )
recur();
echo $a . “, “;
}
function recur() {
global $a;
$a++;
// how did I get here?
echo “\n\n\n”;
debug_print_backtrace();
if( $a < 10 )
iterate();
}
iterate();
# OUTPUT:
#0 recur() called at [C:\htdocs\php_stuff\index.php:8]
#1 iterate() called at [C:\htdocs\php_stuff\index.php:25]
#0 recur() called at [C:\htdocs\php_stuff\index.php:8]
#1 iterate() called at [C:\htdocs\php_stuff\index.php:21]
#2 recur() called at [C:\htdocs\php_stuff\index.php:8]
#3 iterate() called at [C:\htdocs\php_stuff\index.php:25]
#0 recur() called at [C:\htdocs\php_stuff\index.php:8]
#1 iterate() called at [C:\htdocs\php_stuff\index.php:21]
#2 recur() called at [C:\htdocs\php_stuff\index.php:8]
#3 iterate() called at [C:\htdocs\php_stuff\index.php:21]
#4 recur() called at [C:\htdocs\php_stuff\index.php:8]
#5 iterate() called at [C:\htdocs\php_stuff\index.php:25]

7. metaphone()

这个函数返回单词的metaphone值,相同读音的单词具有相同的metaphone值,也就是说这个函数可以帮你判断两个单词的读音是否 相同。不过对中文就无效了。。。

8. natsort()

natsort()能将一个数组以自然排序法 进行排列,直接看个例子吧:

$items = array(
“100 apples”, “5 apples”, “110 apples”, “55 apples”
);
// normal sorting:
sort($items);
print_r($items);
# Outputs:
# Array
# (
# [0] => 100 apples
# [1] => 110 apples
# [2] => 5 apples
# [3] => 55 apples
# )
natsort($items);
print_r($items);
# Outputs:
# Array
# (
# [2] => 5 apples
# [3] => 55 apples
# [0] => 100 apples
# [1] => 110 apples
# )

9. levenshtein()

Levenshtein() 告诉你两个单词之间的“距离”。它告诉你如果想把一个单词变成另一个单词,需要插入、替换和删除多少字母。

看个例子吧:

$dictionary = array(
“php”, “javascript”, “css”
);
$word = “japhp”;
$best_match = $dictionary[0];
$match_value = levenshtein($dictionary[0], $word);
foreach($dictionary as $w) {
$value = levenshtein($word, $w);
if( $value < $match_value ) {
$best_match = $w;
$match_value = $value;
}
}
echo “Did you mean the ‘$best_match’ category?”;

10. glob()

glob()会让你觉得用 opendir(), readdir()和closedir()来寻找文件非常蠢。

foreach (glob(“*.php”) as $file)
echo “$file\n”;


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.