zoukankan      html  css  js  c++  java
  • phpDOC

    1.filter_var

     

    <?php
    if(!filter_has_var(INPUT_GET, "email"))
    {
        echo("没有 email 参数");
    }
    else
    {
        if (!filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL))
        {
            echo "不是一个合法的 E-Mail";
        }
        else
        {
            echo "是一个合法的 E-Mail";
        }
    }

      

    $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("年龄必须在 1 到 120 之间。<br>");
    }
    elseif(!$result["email"])
    {
        echo("E-Mail 不合法<br>");
    }
    else
    {
        echo("输入正确");
    }
            if (file_exists("upload/" . $_FILES["file"]["name"]))
            {
                echo $_FILES["file"]["name"] . " 文件已经存在。 ";
            }
            else
            {
                // 如果 upload 目录不存在该文件则将文件上传到 upload 目录下
                move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
                echo "文件存储在: " . "upload/" . $_FILES["file"]["name"];
            }
     
    function convertSpace($string)
    {
        return str_replace("_", ".", $string);
    }
     
    $string = "www_runoob_com!";
     
    echo filter_var($string, FILTER_CALLBACK,
    array("options"=>"convertSpace"));
    

       所谓多态性是指一段程序能够处理多种类型对象的能力,比如说在公司上班,每个月财务发放工资,同一个发工资的方法,在公司内不同的员工或是不同职位的员工,都是通过这个方法发放的,但是所发的工资都是不相同的。所以同一个发工资的方法就出现了多种形态。对于面向对象的程序来说,多态就是把子类对象赋值给父类引用,然后调用父类的方法,去执行子类覆盖父类的那个方法,但在PHP里是弱类型的,对象引用都是一样的不分父类引用,还是子类引用。

    <?php
    // 定义了一个形状的接口,里面有两个抽象方法让子类去实现
    interface Shape {
        function area();
        function perimeter();
    }
     
    // 定义了一个矩形子类实现了形状接口中的周长和面积
    class Rect implements Shape {
        private $width;
        private $height;
     
        function __construct($width, $height) {
            $this->width = $width;
            $this->height = $height;
        }
     
        function area() {
            return "矩形的面积是:" . ($this->width * $this->height);
        }
     
        function perimeter() {
            return "矩形的周长是:" . (2 * ($this->width + $this->height));
        }
    }
     
    // 定义了一个圆形子类实现了形状接口中的周长和面积
    class  Circular implements Shape {
        private $radius;
     
        function __construct($radius) {
            $this->radius=$radius;
        }
     
        function area() {
            return "圆形的面积是:" . (3.14 * $this->radius * $this->radius);
        }
     
        function perimeter() {
            return "圆形的周长是:" . (2 * 3.14 * $this->radius);
        }
    }
     
    // 把子类矩形对象赋给形状的一个引用
    $shape = new Rect(5, 10);
    echo $shape->area() . "<br>";
    echo $shape->perimeter() . "<br>";
     
    // 把子类圆形对象赋给形状的一个引用
    $shape = new Circular(10);
    echo $shape->area() . "<br>";
    echo $shape->perimeter() . "<br>";
    ?>
    

      因为接口是一种特殊的抽象类,里面所有的方法都是抽象方法,所以接口也不能产生实例对象; 它也做为一种规范,所有抽象方法需要子类去实现。

    魔术方法

    http://www.cnblogs.com/phpgo/p/5665463.html

     

  • 相关阅读:
    看云学习文档列表
    linux&&ubutun 21.06使用查询资料
    element-admin 查询资料笔记
    tp6 composer install 报Your requirements could not be resolved to an installable set of packages。
    centos 7 install npm
    centos 7 dev
    解決npm run dev 报: 'webpack-dev-server' 不是内部或外部命令,也不是可运行的程序 或批处理文件 错误
    解決vue-cli · Failed to download repo vuejs-templates/webpack: tunneling socket could not be established, cause=getaddrinfo ENOTFOUND 10809报错问题
    Linux创建命令快捷方式
    JS 闭包写法
  • 原文地址:https://www.cnblogs.com/Crius/p/7225809.html
Copyright © 2011-2022 走看看