PHP面试题
Tip:在测试代码前设置PHP 文件字符编码 header("content-type:text/html;charset=utf-8");
1.
1.1用PHP 获取当前时间并打印,打印格式:2018-2-09 22:19:30
2.
2.1 字符串转数组
$str = "www.baidu.com";
$arr_str = explode('.',$str);
print_r($arr_str); //Array ( [0] => www [1] => baidu [2] => com )
echo '<br />';
print_r(str_split($str)); //Array ( [0] => w [1] => w [2] => w [3] => . [4] => b [5] => a [6] => i [7] => d [8] => u [9] => . [10] => c [11] => o [12] => m )
2.2 数组转字符串
$arr = array('aaa','bbb','ccc');
print_r(implode(',',$arr)); //aaa,bbb,ccc
echo '<br />';
print_r(join('-',$arr)); //aaa-bbb-ccc
2.3 字符串截取
$str = "a,b,b,d.e,f.g/h?";
print_r(substr($str,0,3)); //a,b 单字节截取
echo '<br />';
$mb_str = "你好北京哈哈哈哈哈哈哈";
print_r(mb_substr($mb_str,0,3)); //你 多字节截取
echo '<br />';
print_r(mb_strcut($mb_str,0,6)); //你好 多字节截取
2.4 字符串替换
$date = '02/26/2018';
echo preg_replace('/(\d+)\/(\d+)\/(\d+)/','$3/$1/$2',$date); //2003/08/26
下一篇: python机器学习之决策树分类详解