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()

PHP Error 和 Logging 函数

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

$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()能将一个数组以自然排序法进行排列,直接看个例子吧: natcasesort()

$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 “$f

10个你可能从未用过的PHP函数(转)的更多相关文章

  1. 第10天:apply和call、bind、函数作为参数、返回值使用、闭包、递归的样例

    apply和call apply和call都可以改变this的指向 函数的调用,改变this的指向 函数名字.apply(对象,[参数1,参数2,.....]) 方法名字.apply(对象,[参数1, ...

  2. Python 3 实现数字转换成Excel列名(10进制到26进制的转换函数)

    背景: 最近在看一些Python爬虫的相关知识,讲爬取的一些数据写入到Excel表中,当时当列的数目不确定的情况下,如何通过遍历的方式讲爬取的数据写入到Excel中. 开发环境: Python 3  ...

  3. 10.PHP内核探索:Apache运行与钩子函数

    Apache是目前世界上使用最为广泛的一种Web Server,它以跨平台.高效和稳定而闻名.按照去年官方统计的数据,Apache服务器的装机量占该市场60%以上的份额.尤其是在 X(Unix/Lin ...

  4. 史上自定义 JavaScript 函数Top 10

    http://www.dustindiaz.com/top-ten-javascript/     发布:wpulog | 发布时间: 2010年4月9日 10个被使用的最普遍的用户自定义函数,add ...

  5. Python 10 —— 杂

    Python 10 —— 杂 科学计算 NumPy:数组,数组函数,傅里叶变换 SciPy:依赖于NumPy,提供更多工具,比如绘图 绘图 Matplitlib:依赖于NumPy和Tkinter

  6. 这10道javascript笔试题你都会么

    1.考察this var length = 10; function fn() { console.log(this.length); } var obj = {   length: 5, metho ...

  7. 第10章 同步设备I/O和异步设备I/O(1)_常见设备及CreateFile函数

    10.1 打开和关闭设备 10.1.1 设备的定义——在Windows中可以与之进行通信的任何东西. (1)常见设备及用途 设备 用途 用来打开设备的函数 文件 永久存储任何数据 CreateFile ...

  8. C Primer Plus(第五版)10

    第 10 章 数组和指针 在本章中你将学习下列内容: · 关键字: static (静态) · 运算符: & * (一元) · 创建与初始化数组的方法. · 指针(基于已学的基础知识)及指针和 ...

  9. 传智播客C语言视频第一季(有效下载期为10.1-10.7,10.8关闭)

     J:\传智播客_尹成_C语言从菜鸟到高手├─传智播客_尹成_C语言从菜鸟到高手_第一章C语言概述A│      第一讲1.1C语言第一阶段.mp4│      第二讲1.2c语言入门教程.mp4 ...

随机推荐

  1. codevs3731 寻找道路

    方向dfs判定是否可行,spfa跑最短路. noip水题,wa好几次. #include<cstdio> #include<algorithm> #include<cst ...

  2. SpringContextHolder 静态持有SpringContext的引用(如何取得Spring管理的bean )

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  3. amoeba安装与实现amoeba for mysql读写分离

    运行环境 l  CentOS6.3 l  Jdk1.6.0_30 l  amoeba-mysql-binary-2.2.0 l  amoeba:192.168.88.17 l  master1:192 ...

  4. EntityFramework程序集版本不同

    问题: Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definitions */ table.MsoNormalT ...

  5. 使用ServiceStackRedis链接Redis简介

    注:关于如何在windows,linux下配置redis,详见这篇文章:) 目前网上有一些链接Redis的C#客户端工具,这里介绍其中也是目前我们企业版产品中所使用的ServiceStackRedis ...

  6. javascript-实现日期大写

    <script language="javascript"> $(document).ready(function() { //定义中文数组 var chinese = ...

  7. js中的继承2--原型继承

    一. 原型与构造函数 Js所有的函数都有一个prototype属性,这个属性引用了一个对象,即原型对象,也简称原型.这个函数包括构造函数和普通函数,我们讲的更多是构造函数的原型,但是也不能否定普通函数 ...

  8. shell ftp上传下载文件

    1. ftp自动登录批量下载文件. #####从ftp服务器上的/home/data 到 本地/home/databackup#### #!/bin/bash ftp -n<<! open ...

  9. 利用python进行折线图,直方图和饼图的绘制

    我用10个国家某年的GDP来绘图,数据如下: labels   = ['USA', 'China', 'India', 'Japan', 'Germany', 'Russia', 'Brazil', ...

  10. leetcode—Same Tree

    1.题目描述 Given two binary trees, write a function to check if they are equal or not.   Two binary tree ...