php函数练习20191031
<?php
$str="what is you name?";
$arr=array('i','s');
$arr_1=array('s','i');//是先后替换的。
echo str_replace($arr,$arr_1,$str);//(筛选替换数,替换数,本来的string)
echo "<br/>";
echo substr_replace($str,"a",0,4);
echo "<br/>";
//翻转
echo strrev($str);
echo "<br/>";
//变量的比较 1前面的数大 -1后面的数大 0为相等
//通常0为false 1、-1为true
$a="a2.mkv";
$b="a12.mkv";
//按位比较
echo strcmp($a,$b);// 1 0 -1
echo "<br/>";
//自然比较
echo strnatcmp($a,$b);// 1 0 -1
$str="how oLD aRE yOu!!";
echo strtoupper($str);
echo "<br />";
echo strtolower($str);
echo "<br />";
echo ucfirst($str);
echo "<br />";
echo ucwords($str);
echo "<br />";
//打星号
for($i=1;$i<=9;$i++){
echo str_repeat("* ",$i);
echo "<br />";
}
$str="hello";
echo md5($str);//crypt($str,'kk');//加密
echo "<br />";
$str="<font color=red size=6>重庆</font>";
echo htmlspecialchars($str);//避免注入攻击
echo addslashes("'ds ' sd'");;//避免注入攻击(前加/)
echo "<br />";
//加密
echo base64_encode($str);
echo "<br/>";
//解密
echo base64_decode('QUFmdHA6Ly9zb2Z0OjgwQHh6Lmk1MzAuY24vM0RzTUFY77yI5a6k5YaF5aSW6K6+6K6h44CB5b2x6KeG5Yqo55S744CB5bu6562R6K6+6K6h77yJLzNEc21heDIwMTEvM2RzbWF4IDIwMTHvvIgzMu+8iS56aXBaWg==');
echo "<br/>";
?>
<?php
//检测匹配结果
$str="20178767d";
$preg='/^(2017)\d{4}[adfh]$/';
if(preg_match($preg,$str)){
echo "配";
}else{
echo "不配";
}
$str1="杜万鹏";
$preg1='/^(杜)*/';
if(preg_match($preg1,$str1)){
echo "儿";
}else{
echo "a";
}
//匹配符合规则的字符串
// $str="454543520179967hfytfy";
// $preg='/(2017)\d{4}[adfh]/';
// preg_match($preg,$str,$rst);
// print_r($rst);
//数组匹配过滤
// $arr=[3.14,3.5,6.7,18.24,9.36,6.7];
// $p='/^\d{1}\.\d{2}$/';
// $rst=preg_grep($p,$arr);
// print_r($rst);
?>