php课程 6-24 字符串函数有哪些(复习)

php课程 6-24 字符串函数有哪些(复习)

一、总结

一句话总结:

二、php课程 6-24 字符串函数有哪些(复习)

上次复习:
-----------------------------------------
字符串函数:

1.字符串的处理介绍

$str='abc';

2.常用的字符串输出函数

echo
print
printf
sprintf
var_dump()
print_r()

3.常用的字符串格式化函数

trim();
ltrim();
rtrim();
strip_tags();
htmlspecialchars();
htmlspecialchars_decode();
addslashes();
stripslashes();
nl2br();
str_pad();
str_repeat();
strtolower();
strtoupper();
ucfirst();
ucwords();
strlen();
strrev();
number_format();
md5();
str_shuffle();
str_split();
substr();
mb_substr();
str_replace();
strpos();
strrpos();
basename();
dirname();
pathinfo();
parse_url();
parse_str();

今天内容:
-----------------------------------------------------
字符串函数:

1.字符串的处理介绍

2.常用的字符串输出函数

3.常用的字符串格式化函数

4.字符串比较函数

5.正则表达式在字符串中的应用

6.与perl兼容的正则表达式函数

字符串定义:

$str='hello world!';

输出字符串:

echo $str;
print $str;
printf('--%s--',$str);
sprintf('--%s--',$str);

字符串连接符:

'<h2>'.$str.'</h2>';

字符串常用函数:

1.去除空格和字符串填补函数

ltrim()
rtrim()
trim()
str_pad()
str_repeat()

2.字符串大小写转换函数

strtolower()
strtoupper()
ucfirst()
ucwords()

3.与html标签相关联的字符串函数

nl2br()
strip_tags()
htmlspecialchars()
htmlspecialchars_decode()
addslashes()
stripslashes()

4.其他字符串格式化函数

strrev()
strlen()
number_format()
md5()
str_shuffle()

5.字符串的分割与拼接

explode()
implode()
join()
str_split();

6.字符串的截取

substr()

7.字符串的查找

strpos()
strrpos($str,'w')

8.字符串的替换

str_replace()

9.多字节处理函数

mb_substr($str,0,7,"utf-8");

10.路径处理函数

dirname();
basename();
pathinfo();
parse_url();
parse_str();

正则的使用场景:

1.检查手机格式

/^d{11}$/

2.检查邮箱格式

/^w+@w+.w+$/

3.检查手机是否是以139开头

/^139d{8}$/

4.复杂的字符串替换环境

/(d+)-(d+)+(d+)/

原文地址:https://www.cnblogs.com/Renyi-Fan/p/9179474.html