08_基本函数

来源:互联网 发布:联想y5070优化教程 编辑:程序博客网 时间:2024/05/22 00:08

定义函数

 function f(){

}

调用函数 f();


可变函数

function f(){

}

$f1='f';

$f1();

匿名函数


$f=function ($str){

echo $str;

};

$f("helloworld");


函数的局部变量

function t(){

$m="hello";

$s=function($a) user ($m){

echo $m

}

}


基本函数

$str="helloworld";

int strlen($str);//用于计算str的长度

header('Contetn-type;text/html:charset=utf-8');

strtoupper($str);//字母转换大写

strtolower($str);//字母全部小写

ucfirst($str);首字母大写

uworlds($str);每个单词大写

str_replace('new','old',$str);

str_ireplace('new','old',$str);

htmlspecialchars($str);

trim();

ltrim();

rtrim();

strpos($str1,$str2);//计算str1的第一次出现的位置

stripos();//不区分大小写

strrpos();

strripos();//最后一次

substr($str,int start,int length);截取

strstr();

stristr();

strchr();

$str1='asdcfsfc';

$str2='c';

strchr($str1,$str2);//cfsfc

strichr($str1,$str2);//c


strrev($str);取反

md5($str);加密

str_shuffle($str);//打乱

explode($str);//分割

implode($str);//结合数组

sprintf();格式化字符串


数学函数

ceil (2.7)=3;

float(2.7)=2;

pow(2,3)=8;

sqrt(4)=2;

min($arr);

max();

rand(1,100);

mt_rand(1,100);

round(66.564,2)=66.56;


时间函数

number_format();

fmod(7.8,3)=1.8

echo date(Y-m-d H:i:s);

date_default_timezone_set(Asia/Shanghai);//设置时区

date_default_timezone_get();//获得时区

time();时间戳

strtotime('-3 weeks');//时间上三周

microtime();




原创粉丝点击