zoukankan      html  css  js  c++  java
  • php实用函数

    ①parse_str

    将查询字符串解析到变量中:

    <?php
    parse_str("name=Bill&age=60");
    echo $name."<br>";
    echo $age;
    ?>

    运行结果:

    Bill
    60
    

      数组参数:

    <?php
    parse_str("name=Bill&age=60",$myArray);
    print_r($myArray);
    ?>

    运行结果:

    Array ( [name] => Bill [age] => 60 )

    ②preg_replace_callback

    对正则匹配的内容用回调函数执行的结果进行替换:

    // 将文本中的年份增加一年.
    $text = "April fools day is 04/01/2002
    ";
    $text.= "Last christmas was 12/24/2001
    ";
    // 回调函数
    function next_year($matches)
    {
        // 通常: $matches[0]是完成的匹配
        // $matches[1]是第一个捕获子组的匹配
        // 以此类推
         //$matches[1]是(d{2}/d{2}/) 匹配到的内容 : 在上面的文本中是 04/01/   和  12/24/
         //$matches[1]是(d{4})        匹配到的内容 : 在上面的文本中是 2002   和    2001
        return $matches[1].($matches[2]+1);
    }
    echo preg_replace_callback(
        "|(d{2}/d{2}/)(d{4})|",
        "next_year",
        $text);

    ③htmlspecialchars_decode() ;

    当json_decode解码无效时,可以试下这个函数。

    实例
    把预定义的 HTML 实体 "<"(小于)和 ">"(大于)转换为字符:
    
    <?php
    $str = "This is some <b>bold</b> text.";
    echo htmlspecialchars_decode($str);
    ?>
    上面代码的 HTML 输出如下(查看源代码):
    
    <!DOCTYPE html>
    <html>
    <body>
    This is some <b>bold</b> text.
    </body>
    </html>
    上面代码的浏览器输出如下:
    
    This is some bold text.
    

      

    ④array_map

    对数组里面的每个元素执行回调方法并且返回,。

    todo  array_map
    function Sum($n){
        $sum=0;
        for($i=1;$i<=$n;$i++){
            $sum+=$i;
        }
        return $sum;
    }
    $array=array(125,1545,1211,100);
    var_dump(array_map("sum",$array));
    

    ⑤array_search

    array_search() 函数在数组中搜索某个键值,并返回对应的键名。

    <?php
    $a=array("a"=>"red","b"=>"green","c"=>"blue");
    echo array_search("red",$a);
    ?>

  • 相关阅读:
    OSCP Learning Notes Buffer Overflows(3)
    OSCP Learning Notes Buffer Overflows(5)
    OSCP Learning Notes Exploit(3)
    OSCP Learning Notes Exploit(4)
    OSCP Learning Notes Exploit(1)
    OSCP Learning Notes Netcat
    OSCP Learning Notes Buffer Overflows(4)
    OSCP Learning Notes Buffer Overflows(1)
    OSCP Learning Notes Exploit(2)
    C++格式化输出 Learner
  • 原文地址:https://www.cnblogs.com/wqyn/p/8681154.html
Copyright © 2011-2022 走看看