str_replace(find,replace,string,count)
count参数是统计被替换的次数
字符串的替换
// 第一个参数:要被地替换的文字
// 第二个参数:替换内容
// 第三个参数:替换源,从那个字符串中替换
echo str_replace("源","缘","我是源字符串",$count);
echo "<br/>";
echo $count;
// 输出结果:我是缘字符串
// 1substr(string,start,length)
字符串的截取
// 第一个参数:源字符串
// 第二个参数:从什么地方开始截取,第一个字符是从0开始的
// 第三个参数:截取的长度
echo substr("There are no user contributed notes for this page.", 0,8);
echo "
";
// 结果:There arstrlen() 返回字符串的长度
ucwords()把字符串中每个单词的首字符转换为大写。
ucfirst()把字符串中的首字符转换为大写。
trim()移除字符串两侧的空白字符和其他字符。
substr_replace(string,replacement,start,length)
字符串的替换,从什么地方开始替换,和替换几位
echo substr_replace("There are no user contributed notes for this page.", "yes", 10,2);
echo "
";
// 结果:There are yes user contributed notes for this page.
// start是开始替换的位置,
// length可选参数,其它的必选,从原文中替换掉几位,这里是2.那么就吧"no"这两位替换掉了substr_count()计算子串在字符串中出现的次数。
strtoupper()把字符串转换为大写字母。
strtolower()把字符串转换为小写字母。
strstr()查找字符串在另一字符串中的第一次出现(对大小写敏感)。
strrev()反转字符串。字符串倒着出现
strrchr()查找字符串在另一个字符串中最后一次出现。
strcmp()比较两个字符串(对大小写敏感)。
返回值:
本函数返回:
- 0 - 如果两个字符串相等
- <0 - 如果 string1 小于 string2
- >0 - 如果 string1 大于 string2
echo strcmp("Hello world!","Hello world!"); // 两字符串相等
echo strcmp("Hello world!","Hello"); // string1 大于 string2
echo strcmp("Hello world!","Hello world! Hello!"); // string1 小于 string2str_word_count()计算字符串中的单词数。
str_split()把字符串分割到数组中。
str_repeat()把字符串重复指定的次数。
str_pad() 函数把字符串填充为新的长度。
str_pad(string,length,pad_string,pad_type)



similar_text() 函数计算两个字符串的相似度。
该函数也能计算两个字符串的百分比相似度。
注释:levenshtein() 函数比 similar_text() 函数更快。不过,similar_text() 函数通过更少的必需修改次数提供更精确的结果。

crypt(str,salt)
函数返回使用 DES、Blowfish 或 MD5 算法加密的字符串。
没有相应的解密函数。crypt() 函数使用一种单向算法。

echo crypt("qjy");
// 结果:$1$WF4.nb2.$rmQ9gntKLM9FJNU/CwlXV/
// 每次结果都不一样,且无法解密
评论列表(0条)