五、字符串处理
其他
2020-03-21 19:55:16
阅读次数: 0
五、字符串处理
- 去除空格和其他字符
trim()
:去除字符串首尾处的空白字符(或者其他字符)
- trim (string
$str
[, string $character_mask
= " \t\n\r\0\x0B" ]) : string
- 此函数返回字符串
str
去除首尾空白字符后的结果
ltrim()
:删除字符串开头的空白字符(或其他字符)
- ltrim ( string
$str
[, string $character_mask
] ) : string
- 删除字符串开头的空白字符(或其他字符)
rtrim()
:删除字符串末尾的空白字符(或其他字符)
- rtrim ( string
$str
[, string $character_mask
] ) : string
- 该函数删除
str
末端的空白字符(或者其他字符)并返回
- 大小写转换函数
strtoupper()
:将字符串转化为大写
- strtolower ( string
$string
) : string
- 将
string
中所有的字母字符转换为小写并返回
strtolower()
:将字符串转化为小写
- strtoupper ( string
$string
) : string
- 将
string
中所有的字母字符转换为大写并返回
- 字符串查找函数
substr_count()
:计算字符串出现的次数(不会重叠计算)
- substr_count ( string
$haystack
, string $needle
[, int $offset
= 0 [, int $length
]] ) : int
substr_count()
返回子字符串needle
在字符串 haystack
中出现的次数, needle
区分大小写。
strpos()
:查找字符串首次出现的位置
- strpos ( string
$haystack
,mixed$needle
[, int $offset
= 0 ] ) : int
- 返回
needle
在 haystack
中首次出现的数字位置
strstr()
:查找字符串的首次出现
- strstr ( string
$haystack
,mixed$needle
[, bool $before_needle
= FALSE
] ) : string
- 返回
haystack
字符串从 needle
第一次出现的位置开始到 haystack
结尾的字符串
- 字符串替换函数
str_replace()
:子字符串替换
- str_replace (mixed
$search
,mixed$replace
,mixed$subject
[, int &$count
] ) : mixed
- 该函数返回一个字符串或者数组,该字符串或数组是将
subject
中全部的 search
都被 replace
替换之后的结果
- 与HTML标签相关的函数
htmlspecialchars()
:将特殊字符转换为 HTML 实体
- htmlspecialchars ( string
$string
[, int $flags
= ENT_COMPAT | ENT_HTML401 [, string $encoding
= ini_get(“default_charset”) [, bool $double_encode
= TRUE
]]] ) : string
- 某类字符在 HTML 中有特殊用处,如需保持原意,需要用 HTML 实体来表达。 本函数会返回字符转义后的表达。 如需转换子字符串中所有关联的名称实体,使用 htmlentities() 代替本函数。
strip_tags()
:从字符串中去除 HTML 和 PHP 标记
- strip_tags ( string
$str
[, string $allowable_tags
] ) : string
- 该函数尝试返回给定的字符串
str
去除空字符、HTML 和 PHP 标记后的结果。它使用与函数 fgetss() 一样的机制去除标记
- 字符串截取函数
substr()
:返回字符串的子串
- substr ( string
$string
, int $start
[, int $length
] ) : string
- 从第
$start
个字符开始截取
- 字符串分割函数
explode()
:使用一个字符串分割另一个字符串
- explode ( string
$delimiter
, string $string
[, int $limit
] ) : array
- 此函数返回由字符串组成的数组,每个元素都是
string
的一个子串,它们被字符串 delimiter
作为边界点分割出来
str_split()
:将字符串转换为数组
- str_split ( string
$string
[, int $split_length
= 1 ] ) : array
- 将一个字符串转换为数组
发布了5 篇原创文章 ·
获赞 0 ·
访问量 8
转载自blog.csdn.net/ck_15270706753/article/details/105014944