A-A+

一些不常见但很有用的php函数

2009年04月03日 PHP 暂无评论 阅读 1 次

exec(string $command[,array &$output[,int &$return_var]])
 --Execute an external program
   string escapeshellarg(string $arg);
   string escapeshellcmd(string $command);
   void passthru(string $command[,int &$return_va])
 --Execute an external program and display raw output
                                                                                                                                               
  函数exec可以直接执行cmd命令,若有执行结果则返回结果值,同时若写上参数
$output的话则可以把执行结果放入到该数组中. 如果想用户输入的数据被传入
本函数,则需要使用escapeshellarg()或escapeshellcmd()函数来确保用户不能
欺骗系统从而执行任意命令(在安全模式时,命令字符串会被escapeshellcmd()转
义).escapeshellcmd()和escapeshellarg()把用户输入命令进行转义过滤.
                                                                                                                                              
    mixed call_user_func_array(callback $function,array $param_arr);
--Call a user function given with an array of parameters
                                                                                                                                              
<?php
function debug($var, $val)
{
    echo "***DEBUGGINGnVARIABLE: $varnVALUE:";
    if (is_array($val) || is_object($val) || is_resource($val)) {
        print_r($val);
    } else {
        echo "n$valn";
    }
    echo "***n";
}
                                                                                                                                              
$c = mysql_connect();
$host = $_SERVER["SERVER_NAME"];
                                                                                                                                              
call_user_func_array('debug', array("host", $host));
call_user_func_array('debug', array("c", $c));
call_user_func_array('debug', array("_POST", $_POST));
?>
                                                                                                                                              
    mixed call_user_func(callback $function[,mixed $parameter[,mixed $...]])
--Call a user function given by the first parameter
<?php
function increment(&$var)
{
    $var++;
}
                                                                                                                                              
$a = 0;
call_user_func('increment', $a);
echo $a; // 0
                                                                                                                                              
call_user_func_array('increment', array(&$a)); // You can use this instead>
echo $a; // 1
?>
                                                                                                                                              >
    int func_num_args(void) -- Returns the number of arguments passed to the function>
                                                                                                                                              
    bool function_exists(string $function_name)
-- Return TRUE if the given function has been defined.
                                                                                                                                              
    array func_get_args(void)--Returns an array comprising a function's argument list
                                                                                                                                              
    mixed func_get_arg(int $arg_num) -- Return an item from the argument list
                                                                                                                                              
    string create_function(string $args,string $code)
--Creates an anonymous(无记录的) function from the parameters passwd,and return a
unique(独一无二的) name for it.

 

给我留言

Copyright © 浩然东方 保留所有权利.   Theme  Ality 07032740

用户登录