php函数研究

<?php
//$number = range(0,50,10);
//print_r ($number);
//生成一个自增的数组
header("Content-type:text/html;charset=utf-8");
/*
 * 
 * 类/对象
 * 
__autoload — 尝试加载未定义的类
call_user_method_array — 调用一个用户方法,同时传递参数数组(已废弃)
call_user_method — 对特定对象调用用户方法(已废弃)
class_alias — 为一个类创建别名
class_exists — 检查类是否已定义
get_called_class — 后期静态绑定("Late Static Binding")类的名称
get_class_methods — 返回由类的方法名组成的数组
get_class_vars — 返回由类的默认属性组成的数组
get_class — 返回对象的类名
get_declared_classes — 返回由已定义类的名字所组成的数组
get_declared_interfaces — 返回一个数组包含所有已声明的接口
get_declared_traits — 返回所有已定义的 traits 的数组
get_object_vars — 返回由对象属性组成的关联数组
get_parent_class — 返回对象或类的父类名
interface_exists — 检查接口是否已被定义
is_a — 如果对象属于该类或该类是此对象的父类则返回 TRUE
is_subclass_of — 如果此对象是该类的子类,则返回 TRUE
method_exists — 检查类的方法是否存在
property_exists — 检查对象或类是否具有该属性
trait_exists — 检查指定的 trait 是否存在
 * 
 */


//function __autoload($classname) {
//    $filename = "./". $classname .".php";
//    include_once($filename);
//}
//
//// we've called a class ***
//$obj = new myClass();



//class foo { }
//
//class_alias('foo', 'bar');
//
//$a = new foo;
//$b = new bar;
//
//// the objects are the same
//var_dump($a == $b, $a === $b);
//var_dump($a instanceof $b);
//
//// the classes are the same
//var_dump($a instanceof foo);
//var_dump($a instanceof bar);
//
//var_dump($b instanceof foo);
//var_dump($b instanceof bar);
//instanceof判断变量是不是继承了后面的类


//if (class_exists('MyClass')) {
//    $myclass = new MyClass();
//}



//class foo {
//    static public function test() {
//        var_dump(get_called_class());
//    }
//}
//
//class bar extends foo {
//}
//
//foo::test();
//bar::test();




//class myclass {
//    // constructor
//    function myclass33()
//    {
//        return(true);
//    }
//
//    // method 1
//    function myfunc1()
//    {
//        return(true);
//    }
//
//    // method 2
//    function myfunc2()
//    {
//        return(true);
//    }
//}
//
//$class_methods = get_class_methods('myclass');
//// or
//$class_methods = get_class_methods(new myclass());
//
//foreach ($class_methods as $method_name) {
//    echo "$method_name
";
//}



//class myclass {
//
//    var $var1; // 此变量没有默认值……
//    var $var2 = "xyz";
//    var $var3 = 100;
//    private $var4; // PHP 5
//
//    // constructor
//    function myclass1() {
//        // change some properties
//        $this->var1 = "foo";
//        $this->var2 = "bar";
//        return true;
//    }
//
//}
//
//$my_class = new myclass();
//echo get_class($my_class);
//$class_vars = get_class_vars(get_class($my_class));
//
//foreach ($class_vars as $name => $value) {
//    echo "$name : $value
";
//}

//返回所有的类名
//print_r(get_declared_classes());



//print_r(get_declared_interfaces());




//class dad {
//    function dad()
//    {
//    // implements some logic
//    }
//}
//
//class child extends dad {
//    function child()
//    {
//        echo "I'm " , get_parent_class($this) , "'s son
";
//    }
//}
//
//class child2 extends dad {
//    function child2()
//    {
//        echo "I'm " , get_parent_class('child2') , "'s son too
";
//    }
//}
//
//$foo = new child();
//$bar = new child2();




//class WidgetFactory
//{
//  var $oink = 'moo';
//}
//
//// create a new object
//$WF = new WidgetFactory();
//
//if (is_a($WF, 'WidgetFactory')) {
//  echo "yes, $WF is still a WidgetFactory
";
//}



//$directory = new Directory('.');
//var_dump(method_exists($directory,'read'));






/*
 * 
call_user_func_array — 调用回调函数,并把一个数组参数作为回调函数的参数
call_user_func — 把第一个参数作为回调函数调用
create_function — Create an anonymous (lambda-style) function
 * create_function — 创建一匿名方法lambda_XXX风格
 * 
forward_static_call_array — Call a static method and pass the arguments as array
 * forward_static_call_array — 调用一个静态方法和传递实参数组
 * 
forward_static_call — Call a static method
 * forward_static_call — 调用一个静态方法
 * 
func_get_arg — 返回参数列表的某一项
func_get_args — 返回一个包含函数参数列表的数组
func_num_args — Returns the number of arguments passed to the function
 * func_num_args — 返回参数传递给函数的数量
 * 
function_exists — 如果给定的函数已经被定义就返回 TRUE
get_defined_functions — Returns an array of all defined functions
 * get_defined_functions —返回一个数组定义的所有函数
 * 
register_shutdown_function — Register a function for execution on shutdown
 * register_shutdown_function —注册一个函数执行关闭
 * 
register_tick_function — Register a function for execution on each tick
 * register_tick_function — 登记每个刻度的执行功能
 * 
unregister_tick_function — De-register a function for execution on each tick
 * unregister_tick_function — 去注册一个函数的每个刻度的执行
 * 
 * 
 * 
 */

//function foobar($arg, $arg2) {
//    echo __FUNCTION__, " got $arg and $arg2
";
//}
//class foo {
//    function bar($arg, $arg2) {
//        echo __METHOD__, " got $arg and $arg2
";
//    }
//}
//
//
//// Call the foobar() function with 2 arguments
//call_user_func_array("foobar", array("one", "two"));
//echo '<br>';
//// Call the $foo->bar() method with 2 arguments
//$foo = new foo;
//call_user_func_array(array($foo, "bar"), array("three", "four"));


//error_reporting(E_ALL);
//function increment($var)
//{
//    $var++;
//}
//
//$a = 0;
//call_user_func('increment', $a);
//echo $a."
";
//
//call_user_func_array('increment', array(&$a)); // You can use this instead before PHP 5.3
//echo $a."
";



//$newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');
//echo "New anonymous function: $newfunc";
//echo '<br>';
//echo $newfunc(2, 5);




//class A
//{
//    const NAME = 'A';
//    public static function test() {
//        $args = func_get_args();
//        echo static::NAME, " ".join(',', $args)." 
";
//    }
//}
//
//class B extends A
//{
//    const NAME = 'B';
//
//    public static function test() {
//        echo self::NAME, "
";
//        forward_static_call_array(array('A', 'test'), array('more', 'args'));
//        forward_static_call_array( 'test', array('other', 'args'));
//    }
//}
//
//B::test('foo');
//
//function test() {
//        $args = func_get_args();
//        echo "C ".join(',', $args)." 
";
//    }
//
//   echo function_exists('test');



//function myrow($id, $data)
//{
//    return "<tr><th>$id</th><td>$data</td></tr>
";
//}
//
//$arr = get_defined_functions();
//
//print_r($arr);



//function shutdown()
//{
//    // This is our shutdown function, in 
//    // here we can do any last operations
//    // before the script is complete.
//
//    echo 'Script executed with success', PHP_EOL;
//}
//
//register_shutdown_function('shutdown');














/*
 * 
filter_has_var — Checks if variable of specified type exists
 * filter_has_var — 检查输入变量的指定类型的存在
 * 
filter_id — Returns the filter ID belonging to a named filter
 * filter_id — 返回过滤器ID属于一个名叫过滤器
 * 
filter_input_array — Gets external variables and optionally filters them
 * filter_input_array — 获取多个输入变量,并通过相同的或不同的过滤器对它们进行过滤
 * 
filter_input — Gets a specific external variable by name and optionally filters it
 * filter_input — 获取一个输入变量,并对它进行过滤
 * 
filter_list — Returns a list of all supported filters
 * filter_list — 返回支持的过滤器的所有列表
 * 
filter_var_array — Gets multiple variables and optionally filters them
 * filter_var_array —通过相同的或不同的过滤器来过滤多个变量
 * 
filter_var — Filters a variable with a specified filter
 * filter_var —  通过一个指定的过滤器来过滤单一的变量
 * 
 */

//http://www.test.com/zzz.php?email=1 //Email Found

//if ( !filter_has_var(INPUT_GET, 'email') ) {
//        echo "Email Not Found";
//    }else{
//        echo "Email Found";
//    }


//$filters = filter_list(); 
//foreach($filters as $filter_name) { 
//    echo $filter_name .": ".filter_id($filter_name) ."<br>"; 
//} 

//print_r(filter_list());
//
//下面是支持所有过滤类型
//
//    [0] => int
//    [1] => boolean
//    [2] => float
//    [3] => validate_regexp
//    [4] => validate_url
//    [5] => validate_email
//    [6] => validate_ip
//    [7] => string
//    [8] => stripped
//    [9] => encoded
//    [10] => special_chars
//    [11] => full_special_chars
//    [12] => unsafe_raw
//    [13] => email
//    [14] => url
//    [15] => number_int
//    [16] => number_float
//    [17] => magic_quotes
//    [18] => callback


//$int = 123;
//
//if(!filter_var($int, FILTER_VALIDATE_INT))
// {
// echo("Integer is not valid");
// }
//else
// {
// echo("Integer is valid");
// }



 
// $var=300;
//
//$int_options = array(
//"options"=>array
// (
// "min_range"=>0,
// "max_range"=>256
// )
//);
//
//if(!filter_var($var, FILTER_VALIDATE_INT, $int_options))
// {
// echo("Integer is not valid");
// }
//else
// {
// echo("Integer is valid");
// }



//http://www.test.com/zzz.php?age=10&email=222@qq.com&name=rrdsadsadas

//$filters = array
// (
// "name" => array
//  (
//  "filter"=>FILTER_SANITIZE_STRING
//  ),
// "age" => array
//  (
//  "filter"=>FILTER_VALIDATE_INT,
//  "options"=>array
//   (
//   "min_range"=>1,
//   "max_range"=>120
//   )
//  ),
// "email"=> FILTER_VALIDATE_EMAIL,
// );
//
//$result = filter_input_array(INPUT_GET, $filters);
//
//if (!$result["age"])
// {
// echo("Age must be a number between 1 and 120.<br />");
// }
//elseif(!$result["email"])
// {
// echo("E-Mail is not valid.<br />");
// }
//else
// {
// echo("User input is valid");
// }



//function convertSpace($string)
//{
//return str_replace("_", " ", $string);
//}
//
//$string = "Peter_is_a_great_guy!";
//
//echo filter_var($string, FILTER_CALLBACK, array("options"=>"convertSpace"));




/*
 * 
 * 字符类型检测
 * 
ctype_alnum — 做字母和数字字符检测
ctype_alpha — 做纯字符检测 包括大小写
ctype_cntrl — 做控制字符检测
ctype_digit — 做纯数字检测
ctype_graph — 做可打印字符串检测,空格除外 比如
	会被过滤
ctype_lower — 做小写字符检测
ctype_print — 做可打印字符检测 和ctype_graph很类似,但是包括空格
ctype_punct — 检测可打印的字符是不是不包含空白、数字和字母
ctype_space — 做空白字符检测
ctype_upper — 做大写字母检测
ctype_xdigit — 检测字符串是否只包含十六进制字符
 * 
 */





//$strings = array('AbCd1zyZ9', 'foo!#$bar');
//foreach ($strings as $testcase) {
//    if (ctype_alnum($testcase)) {
//        echo "只含有字母和数字";
//        echo  '<br>';
//    } else {
//        echo "不止包含字母和数字";
//        echo  '<br>';
//    }
//}



//$strings = array('KjgWZC', 'arf12');
//foreach ($strings as $testcase) {
//    if (ctype_alpha($testcase)) {
//         echo "只含有字母";
//         echo  '<br>';
//    } else {
//          echo "不止包含字母";
//          echo  '<br>';
//    }
//}




//$strings = array('string1' => "

	", 'string2' => 'arf12');
//foreach ($strings as $name => $testcase) {
//    if (ctype_cntrl($testcase)) {
//        echo "包含控制字符";
//    } else {
//        echo "不止包含控制字符";
//    }
//}



//$strings = array('1820.20', '10002', 'wsl!12');
//foreach ($strings as $testcase) {
//    if (ctype_digit($testcase)) {
//        echo "只包含纯数字";
//    } else {
//        echo "不只包含纯数字";
//    }
//}



//$strings = array('string1' => "asdf

	", 'string2' => 'arf12', 'string3' => 'LKA#@%.54');
//foreach ($strings as $name => $testcase) {
//    if (ctype_graph($testcase)) {
//        echo "所有字符打印时候都是可见的";
//    } else {
//        echo "不是所有字符打印时候都是可见的";
//    }
//}


//$strings = array('aac123', 'qiutoas', 'QASsdks');
//foreach ($strings as $testcase) {
//    if (ctype_lower($testcase)) {
//        echo "所有字符都是小写";
//    } else {
//        echo "不是所有字符都是小写";
//    }
//}





//$strings = array('string1' => "asdf

	", 'string2' => 'arf12', 'string3' => 'LKA#@%.54');
//foreach ($strings as $name => $testcase) {
//    if (ctype_print($testcase)) {
//        echo "所有字符打印时候都是可见的";
//    } else {
//        echo "不是所有字符打印时候都是可见的";
//    }
//}


//$strings = array('ABasdk!@!$#', '!@ # $', '*&$()');
//foreach ($strings as $testcase) {
//    if (ctype_punct($testcase)) {
//        echo "字符不包含空白、数字和字母";
//    } else {
//        echo "字符包含空白、数字和字母";
//    }
//}


//$strings = array('string1' => "

	", 'string2' => "
arf12", 'string3' => '

	');
//foreach ($strings as $name => $testcase) {
//    if (ctype_space($testcase)) {
//        echo "所有字符打印时候都是可见的";
//    } else {
//        echo "不是所有字符打印时候都是可见的";
//    }
//}

//$strings = array('AKLWC139', 'LMNSDO', 'akwSKWsm');
//foreach ($strings as $testcase) {
//    if (ctype_upper($testcase)) {
//        echo "所有字符都是大写";
//    } else {
//        echo "不是所有字符都是大写";
//    }
//}


//$strings = array('AB10BC99', 'AR1012', 'ab12bc99');
//foreach ($strings as $testcase) {
//    if (ctype_xdigit($testcase)) {
//        echo "所有字符都是十六进制";
//    } else {
//        echo "不是所有字符都是十六进制";
//    }
//}
原文地址:https://www.cnblogs.com/zx-admin/p/4453844.html