php 小函数

/*测试函数效率

**第一个参数为函数名

*/

function test_func($FuncName,$arg1,$arg2,…$argN){

$args = func_get_args();

array_shift($args);

$begin = microtime(true);

call_user_func($FuncName,$args);

function unhtmlentities($string)
{
// replace numeric entities
$string = preg_replace(‘~&#x([0-9a-f]+);~ei’, ‘chr(hexdec(“\\1”))’, $string);
$string = preg_replace(‘~&#([0-9]+);~e’, ‘chr(\\1)’, $string);

// replace literal entities
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}

$end = microtime(true);

echo “func:$FuncName\n args:”.var_export($args,true).”\n cost time”.($end-$begin).”s”;

}

php系统函数

debug_backtrace();

这个函数挺好使的.会打印出一个调用堆栈.以数组的形式列出来.

这样调用

print_r(debug_backtrace());