<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
/*$c = "张三";
$a = "hello{$c}";
$b = 'world{$c}';//单引号里面不能加变量 双引号里面可以加变量
echo $a."<br>";
echo $b;*/
/*public Name(参数列表) //弱类型没有返回值
{
函数体
}*/
/*function Name()
{
echo "aaaa";
}
Name();*/
/*function Test($a,$b)
{
return $a+$b;
}
echo Test(5,6); //可以多写不能少写 */
/*function Test($a=7,$b=8)
{
return $a+$b;
}
echo Test(5,6); //默认是7,8 如果输1个数,会替换第一个,所以这里可以输1个数*/
/*function Test()
{
$attr = func_get_args();
for($i=0;$i<count($attr);$i++)
{
echo "第{$i}个参数是{$attr[$i]}<br>";
}
}
Test(1,2,10,"aa");
*/
//求和函数,func_get_args()是获取参数,返回数组;func_num_args()获取参数的个数
/*function Test()
{
$attr = func_get_args();
$sum = 0;
for($i=0;$i<func_num_args();$i++)
{
$sum = $sum+$attr[$i];
}
return $sum;
}
echo Test(1,2,10);*/
//全局变量
/* $a = 6;
function Test()
{
global $a; //将变量$a作为一个全局变量
$a = $a+10;
echo $a."<br>";
}
Test();
echo $a;*/
//字符串常用函数
//$a = "hello";
//echo strlen($a); //输出字符串的长度
//$b = "Hello";
//echo strcmp($a,$b); //判断两个字符串是否相同,相同返回0,区分大小写
//echo strcasecmp($a,$b);//判断字符串是否相同,不区分大小写
//echo strtolower($b); //转小写
//echo strtoupper($a); //转大写
/*$str = "aaaa|bbbb|cccc|dddd";
$attr = explode("|",$str); //拆分字符串,返回数组
print_r($attr);
echo implode("@",$attr); //将数组拼成字符串*/
//$str = "aabbccddeecc";
//echo substr_replace($str,"mm",0,4); //替换指定位置的字符串
//echo str_replace("cc","mm",$str); //查找替换
//echo substr($str,0,6); //截取字符串
//其它常用函数
//echo rand(1,10); //随机数生成器,可以写范围
//echo time(); //返回当前的日期时间的UNIX时间戳
//echo date("Y-m-d H:i:s:ms",time());格式化日期时间
//echo date("Y-m-d H:i:s:ms");//取当前时间
//$t = strtotime("2016-5-6"); //将字符串转成时间戳
//正则表达式
// /^\d$/ a1vvvv2hhh3
$reg = "/(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}/";
$str = "vv18653378660v18653378665v2h0hh";
//echo preg_replace($reg,"phone",$str); //替换字符串
//print_r(preg_split($reg,$str)); //拆分字符串
$arr = array();
preg_match($reg,$str,$arr); //匹配第一个
preg_match_all($reg,$str,$arr); //匹配所有
print_r($arr);
?>
</body>
</html>