PHP学习笔记六、函数

一、常用字符串函数

字符串类型的特点

1、输出函数

void echo(string $arg1 [,string $...])

2、程序报错后终止继续运行的函数

void die(string status)

3、打印数组

bool print_r(mixed Sexpression [,bool Sreturn])

4、字符串切割函数

array explode(string $separator,string $string [,int $limit])

5、数组元素组合成字符串的函数

string implode(string $str,array $arr)

6、预定义字符串转换成HTML实体的函数

预定义字符串转换成HTML实体的函数

我爱PHP" echo htmlspecialchars($str);//源码显示(

我爱PHP

) ?>

7、过滤PHP和HTML标记函数

string strip_tags(string $str [,string $allowable_tags])

过滤PHP和HTML标记函数

8、去除字符串首尾连续空格的函数

9、将换行符替换成HTML的换行符(<br/>)的函数

string nl2br(string $string [,bool $is_xhtml=true])

10、加密函数md5(不可逆的加密算法)

string md5(string $str [,bool $raw_output=false])

11、加密函数shal(不可逆的加密算法)

string shal(string $str [,bool bool $raw_output=false])

12、字符串替换函数

str_replace


13、数字分组格式化函数

number_format

14、字符串分割函数

str_split

15、字符串截取函数

string substr(string $string,int $start [, int $length])
一般用于英文的截取

16、中文字符串截取、编码转换函数

中文字符串截取

二、日期函数

  • 时间戳就是一个数字
  • 从1970-1-1 0:0:0 (它的时间戳是0)起,每隔一秒时间戳加1
  • 一天的时间戳是86400

1、time函数

获取当前时间戳:echo time()

2、strtotime("时间")

"; echo strtotime("-1 day");//一天前的时间戳 echo strtotime("-1 week"); echo strtotime("-1 month"); echo strtotime("-1 year"); echo strtotime("-1 year -1 month");//减一年零一个月 echo strtotime("2013-1-1 -25 day"); //计算2013-6-7到2013-8-6中间有多少天? echo strtotime("2013-8-6")-echo strtotime("2013-6-7")/86400; ?>

3、date(时间格式[,时间戳=time()])函数

posted @ 2016-01-17 20:24  liujf  阅读(197)  评论(0)    收藏  举报