zoukankan      html  css  js  c++  java
  • PHP自定义函数与字符串处理

    自定义函数:
        1.默认值的函数:
        function Main($a=5,$b=6)
        {
            echo $a*$b;
        }

        2.可变参数的函数:
        function Main()
        {
            for($i=0;$i<func_num_args();$i++)
            {
                $array = func_get_args();
                echo $array[$i]."<br>";
            }    
        }

        3.函数参数化(在其它语言里面称作代理或委托)
        function index2()
        {
            echo "bb";
        }
        @$hanshu = index2;
        $hanshu();

    字符串处理:
        
        strlen("aaa");取字符串的长度 ***
        strcmp("aaa","aaa");比较两个字符串,相同的话输出0,不相同输出-1
        strcasecmp("aaa","AAA");比较两个字符串,不区分大小写
        strtolower("AbCdEfGh");转小写
        strtoupper();转大写
        $array = explode("|",$s);拆分字符串,返回一个字符串的数组 ***
        $s = implode($array);将数组转为字符串
        $s = substr_replace($s,"china",1,2);通过位置替换字符串
        $s = str_replace("l","dog",$s);替换字符串,相当于记事本中的查找替换
        $s = substr($s,4,10);截取字符串,根据开始位置结束位置截取 ***

  • 相关阅读:
    priority of uncertainty
    0523
    6.  Design Partition Guidelines for ThirdParty IP Delivery
    0604
    the categories of constraints
    priority of setup/hold
    SECTION 4: THE TIMEQUEST GUI
    tiny mistake made confusing issues
    fgetcsv 读取csv文件出现问题解决办法
    安卓笔记之配置第一个程序
  • 原文地址:https://www.cnblogs.com/liaoliao/p/5162094.html
Copyright © 2011-2022 走看看