补点另外的
empty($var);
isset($var);
//如果表单未填写返回0
判断表单元素是否为空,两个函数
的printf函数
1:
$var=10.24
printf("this num is %s",$var);
//%s输出字符串类型
this num is 10.24
printf("this num is %.2f",$var);
//%f输出浮点型
this num is 10.24
2:不按照顺序映射变量,但是不常用吧
printf("num2 is %2\$.2f,num1 is %1\$.2f",$num1,$num2);
//%2表示第二个变量
//$.2f两位浮点数
SUBSTR函数:
substr("hello world",1,4);
//1是start 位置
//4是截取的长度,如果不写,默认到字符串结束
//输出ello//默认从0开始
//如果end是负值,表示从字符串后面向前面数
//如果end和start之间因为选值并不存在交叉比如4和-7,则无返回
爆炸函数和破灭函数:
$storage=explode("@","tyust@qq.com");//以@为标志分割
//得到$storage[0]//也就是tyust
//$storage[1]//是qq.com
$myarray=array("tyust","qq.com");
$result=implode("@",$myarray);
//$result是tyust@qq.com
字符串比较的strcmp和strcasecmp
strcmp($str1,$str2);
strcasecmp($str1,$str2);
//strcmp和strcasecmp函数差不多,只是strcasecmp不区分大小写
//如果str1与str2相等则返回0,如果按照字典序str1在str2后面(str1大于str2)则返回正数
//否则负数
匹配字符串:
$var=strstr("hello world","o");
//返回o world
$var=strpos("hello world","o");
//返回找到的第一个位置4
字符串替代:脏话代替....厉害啦
$dirty=array("fuck","bitch");
str_replace($dirty,"***","what the fuck! this is a bitch")
//输出 what the ***! this is a ***