博客
关于我
PHP函数方法
阅读量:793 次
发布时间:2023-03-01

本文共 1232 字,大约阅读时间需要 4 分钟。

补充一个P可以HP的特点函数:动态调用

function t(){

echo "welcome";

}

function t2(){

echo "beatch";

}

$s = 'wel';

$s();//输出了welcome;可以用变量的值调用函数

不加global函数里面的$a和外部的$a无关 加了global就是可以调用全局变量 不推荐使用

function t(){

global $a ;

}

$a = 22;

echo '$a';

time():从1970,0101开始过去多少秒

microtime();这一秒过去多少毫秒 有两行第一行是这一秒过去多少毫秒 第二行是从19700101开始过去多少秒

microtime(true);从1970年0101开始过去多少秒 点 多少毫秒

 

data();

$time=time()

date('Y-m-d 星期N','$time');返回的是现在时间的几几年几月几日星期几 数字格式的可看手册方法 $time可以去掉

gmdate();

gmdate()返回的是时区问题 格林威特时区???

mktime(时分秒月日时);//按照给定的时间计算返回过去多少秒了

strtotime();给字符串解析时间 比如 now指现在就解析过去多少秒了 now +1 day

checkdate(日月年);检测时间是否合法

 

strlen()获取字符串长度\

要解析中文长度:$str='中国'; echo strlen($str,'utf-8');中文长度为2

 

$strpos()是否含有某个字符

$a='abcde'; $b='b'; if(strpos($a,$b)!==false){

echo '含有',$b;

}else

{

echo '不含有',$b;

}

替换字符串:str_replace

$str='hi shit';

echo str_replace('shit','s**t',$str);

 

多个替换:strtr

$str='男人','女人','男孩','女孩';

strtr($str,array('男'=>'女','女'=>'男'));

截取子字符串:substr

$str='abcdefghrjklmn';

substr($str,0,3);//截取了abcb如3 -3从第三个数到倒数第四个开始截取内容

拆分字符串:explode

$str='tech','linux','mysql';

$arr=explode(',',$str);被逗号隔成三个字符串 输出是0角标对应的是什么内容

print_r($arr);

 echo implode($arr,',');将数组对于的字符串 又转换成字符串

 

转载于:https://www.cnblogs.com/hello-web/p/7624939.html

你可能感兴趣的文章
npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
查看>>
npm error Missing script: “server“npm errornpm error Did you mean this?npm error npm run serve
查看>>
npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
查看>>
npm install CERT_HAS_EXPIRED解决方法
查看>>
npm install digital envelope routines::unsupported解决方法
查看>>
npm install 卡着不动的解决方法
查看>>
npm install 报错 EEXIST File exists 的解决方法
查看>>
npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
查看>>
npm install 报错 Failed to connect to github.com port 443 的解决方法
查看>>
npm install 报错 fatal: unable to connect to github.com 的解决方法
查看>>
npm install 报错 no such file or directory 的解决方法
查看>>
npm install 权限问题
查看>>
npm install报错,证书验证失败unable to get local issuer certificate
查看>>
npm install无法生成node_modules的解决方法
查看>>
npm install的--save和--save-dev使用说明
查看>>
npm node pm2相关问题
查看>>
npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
查看>>
npm run build报Cannot find module错误的解决方法
查看>>
npm run build部署到云服务器中的Nginx(图文配置)
查看>>
npm run dev 和npm dev、npm run start和npm start、npm run serve和npm serve等的区别
查看>>