PHP 字符串操作

explode — 使用一个字符串分割另一个字符串 

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

implode — 将一个一维数组的值转化为字符串

string implode ( string $glue , array $pieces )

htmlspecialchars — 将特殊字符转换为 HTML 实体  (XXS)

string htmlspecialchars ( string $string )

htmlspecialchars_decode — 将特殊的 HTML 实体转换回普通字符 (与 htmlspecialchars 相反)

string htmlspecialchars_decode ( string $string )

strip_tags — 从字符串中去除 HTML 和 PHP 标记(和htmlspecialchars不同的是 strip_tags 是直接去除标记,而前者是转义成另外的字符) 

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

md5 — 计算字符串的 MD5 散列值

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

nl2br — 在字符串所有新行之前插入 HTML 换行标记 (能将浏览器不能识别的 \n 或者 \r\n 转化成 </br>)

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

trim — 去除字符串首尾处的空白字符(或者其他字符)

string trim ( string $str [, string $character_mask = " \t\n\r\0\x0B" ] )

strpos — 查找字符串首次出现的位置(stripos 不区分大小写)(通常用于判断字符串中是否包含另一个字符串

 

int stripos ( string $haystack , string $needle [, int $offset = 0 ] )

strrpos — 计算指定字符串在目标字符串中最后一次出现的位置

扫描二维码关注公众号,回复: 190228 查看本文章
int strrpos ( string $haystack , string $needle [, int $offset = 0 ] )

strlen — 获取字符串长度(也可以用来判断字符串是否为空)

int strlen ( string $string )

strtolower — 将字符串转化为小写

string strtolower ( string $string )

strtoupper — 将字符串转化为大写

string strtoupper ( string $string )

substr_count — 计算字串出现的次数

int substr_count ( string $haystack , string $needle [, int $offset = 0 [, int $length ]] )

substr — 返回字符串的子串(返回字符串 string 由 start 和 lenth 参数指定的子字符串)

string substr ( string $string , int $start [, int $length ] )

string

输入字符串。必须至少有一个字符。

start

如果 start 是非负数,返回的字符串将从 string 的 start 位置开始,从 0 开始计算。例如,在字符串 “abcdef” 中,在位置 0 的字符是 “a”,位置 2 的字符串是 “c” 等等。

如果 start 是负数,返回的字符串将从 string 结尾处向前数第 start 个字符开始。

如果 string 的长度小于 start,将返回 FALSE

length

如果提供了正数的 length,返回的字符串将从 start 处开始最多包括 length 个字符(取决于 string 的长度)。

如果提供了负数的 length,那么 string 末尾处的 length 个字符将会被省略(若 start 是负数则从字符串尾部算起)。如果 start 不在这段文本中,那么将返回 FALSE

如果提供了值为 0FALSE 或 NULL 的 length,那么将返回一个空字符串。

如果没有提供 length,返回的子字符串将从 start 位置开始直到字符串结尾。

 

str_replace — 子字符串替换(忽略大小写请用 str_ireplace

mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

search

查找的目标值,也就是 needle。一个数组可以指定多个目标。

replace

search 的替换值。一个数组可以被用来指定多重替换。

subject

执行替换的数组或者字符串。也就是 haystack

如果 subject 是一个数组,替换操作将遍历整个 subject,返回值也将是一个数组。

count

如果被指定,它的值将被设置为替换发生的次数。

 

猜你喜欢

转载自www.cnblogs.com/xiaoliwang/p/8775606.html