"; print_r($mats); echo ""; ?>//匹配ip
"; print_r($mats); echo ""; ?>模式修正符,放在正則表達式的最后面 i,m,s,u,e i :忽略大写和小写 m :视为多行 s :视为一行 u :贪婪模式,最大模式 e :替换的时候用的,能够用函数加工,用于匹配正則表達式中的第一个圆括号
"; print_r($mats); echo ""; ?>m样例 m视为多行
php $str = "Linux and php are lamp or \nlinux is very much"; $ptn = '/^linux/im'; preg_match_all($ptn, $str,$mats); echo "<pre>"; print_r($mats); echo "</pre>"; ?
>
模式修正符"; print_r($mats); echo ""; ?
>
e的使用"; print_r($str2); echo ""; ?
>
向后引用"; print_r($str2); echo ""; ?>五个经常使用函数 1.字符串的匹配与替换 preg_match(); preg_match_all(); preg_grep();做搜索 2.字符串的替换 preg_replace(); 3.字符串的切割 preg_split(); eval让字符串表达式可以运行 preg_grep实例,做搜索:
"; print_r($arr2); echo ""; ?
>
4.数学函数 1.max(); 2.min(); 注意:1.多个数字,2,多个数字组成的数组php echo max(3,45,6,7); echo "<br>"; echo max(array(4,6,8,9)); ?
>
5.日期函数 1.time(); 2.date(); //把时间戳转换为日期 3.strtotime();//把日期转换为时间戳 4.microtime(); //calc打开计算器 时间的起源点:"; echo date("Y-m-d H:i-s w t",0); ?>时间转换为时间戳
php echo strtotime("2014-12-12"); ?>
计算当前时间的详细日期:通过改动时区来查找当前日期:
>
注意:假设每一个改比較麻烦的话,就直接去改动php的配置文件php.ini文件,直接改动里面的date 找见timezone改动为PRC date參数: Y 2014 年全 y 14 年仅仅有后两位 m 03 月份有前导0 n 3 月份没有前导0 d 05 日期有前导0 j 5 日期没有前导0 H 24小时 h 12小时 i 05分钟 s 05秒 w 0-6 周日到周六 t 31 一月多少天 L 是否为闰年 //如何区分平润年 可以被4整除,同一时候假设能被100整除的话,那就必须被400整除,此时它就是闰年microtime() 微秒 计算脚本的执行时间:
实例:万年历 万年历技术点 1.几年几月几日 2.周日到周六 3.1号是星期几 4.这个月有多少天 5.下一年和上一年 6.下一月和上一月 万年历代码:
php //改动字符编码 //header("content-type:text/html;charset=utf-8"); date_default_timezone_set("PRC"); //获取当前年 $year = $_GET['y']?$_GET['y']:date('Y'); //获取当前月 $month = $_GET['m']?
$_GET['m']:date('m'); //获取获取当前月有多少天 $days = date('t',strtotime("{$year}-{$month}-1"));//里面必须用双引號 //当前一号是周几 $weeks = date('w',strtotime("{$year}-{$month}-1")); //全部有内容居中 echo "<center>"; //输出表头 echo "<h2>{$year}年{$month}月</h2>"; //输出日期表格 echo "<table width='700px' border='1px'>"; //输出第一行 echo "<tr>"; //表头单元格由th来创建 echo "<th>日</th>"; echo "<th>一</th>"; echo "<th>二</th>"; echo "<th>三</th>"; echo "<th>四</th>"; echo "<th>五</th>"; echo "<th>六</th>"; echo "</tr>"; //開始铺表格 for($i = 1 - $weeks;$i <= $days;){ echo "<tr>"; for ($j=0; $j < 7; $j++) { if ($i > $days || $i < 1) { echo "<td> </td>"; } else{ echo "<td>{$i}</td>"; } $i++; } echo "</tr>"; } echo "</table>"; //实现一下上一年和上一月 if($month == 1){ $prevyear = $year - 1; $prevmonth = 12; } else{ $prevyear = $year; $prevmonth = $month -1; } if($month == 12){ $nextyear = $year + 1; $nextmonth = 1; } else{ $nextyear = $year; $nextmonth = $month + 1; } //输出上一月和下一月的button echo "<h2><a href = 'index.php?y={$prevyear}&m={$prevmonth}'>上一月</a>|<a href='index.php?
y={$nextyear}&m={$nextmonth}'>下一月</a></h2>"; echo "</center>"; ?
>
PHP的错误处理 1.关闭和开启报错 2.错误报告级别 3.错误报告地方 关闭和开启报错 E_ALL E_ERROR //严重错误 E_WARNING //警告错误 E_PARSE //语法错误 E_NOTICE //提示错误 关闭错误 display_error = off 报什么级别的错: error_reporting = E_ALL error_reporting = E_ALL & ~E_NOTICE //报全部错误,可是除了提示错误 报错地方: //是否从浏览器报错 display_error = off //是否把错误输出到一个自己定义日志文件里 log_errors = on error_log = d:\phplogs\php.log 转载请注明出处: http://blog.csdn.net/junzaivip