任选不少于20个字符串函数进行练习,从参数,返回值,应用场景上进行分析和记忆, (课堂上讲过的不得再写了)

PHP 字符串函数是 PHP 核心的组成部分。无需安装即可使用这些函数。

函数描述
addcslashes()返回在指定的字符前添加反斜杠的字符串。
addslashes()返回在预定义的字符前添加反斜杠的字符串。
chop()删除字符串右侧的空白字符或其他字符。
convert_uudecode()解码 uuencode 编码字符串。
convert_uuencode()使用 uuencode 算法对字符串进行编码。
crypt()单向的字符串加密法(hashing)。
html_entity_decode()把 HTML 实体转换为字符。
htmlentities()把字符转换为 HTML 实体。
join()implode() 的别名。
lcfirst()把字符串的首字符转换为小写。
localeconv()返回本地数字及货币格式信息。
ltrim()移除字符串左侧的空白字符或其他字符。
md5_file()计算文件的 MD5 散列。
money_format()返回格式化为货币字符串的字符串。
quoted_printable_decode()把 quoted-printable 字符串转换为 8 位字符串。
quoted_printable_encode()把 8 位字符串转换为 quoted-printable 字符串。
setlocale()设置地区信息(地域信息)。
str_pad()把字符串填充为新的长度。
str_word_count()计算字符串中的单词数。
wordwrap()打断字符串为指定数量的字串
vsprintf()把格式化字符串写入变量中。
vprintf()输出格式化的字符串。
vfprintf()把格式化的字符串写到指定的输出流。

相关资料来源于:https://www.w3school.com.cn/php/php_ref_string.asp

addcslashes()字符串

返回在指定的字符前添加反斜杠

  1. <?php
  2. $str = addcslashes("K009 W998 V555 K664 K338","K");
  3. echo($str);
  4. ?> //输出\K009 W998 V555 \K664 \K338

addslashes()字符串

返回在预定义的字符前添加反斜杠的字符串。

  1. <?php
  2. //在每个双引号(")前添加反斜杠:
  3. $str = addslashes('Beijing is the "capital" of China');
  4. echo($str);
  5. echo '<hr>';
  6. //输出:Beijing is the \"capital\" of China
  7. //向字符串中的预定义字符添加反斜杠:
  8. $str = "Who's Bill Gates?";
  9. echo $str . " This is not safe in a database query.<br>";
  10. echo addslashes($str) . " This is safe in a database query.";
  11. //输出:Who's Bill Gates? This is not safe in a database query.
  12. //Who\'s Bill Gates? This is safe in a database query.

chop() 字符串函数

chop() 函数移除字符串右端的空白字符或其他预定义字符。

  1. <?php
  2. //从字符串右端移除字符:
  3. $str = "Welcome to Beijing!";;
  4. echo $str . "<br>";
  5. echo chop($str,"Beijing!");
  6. echo'<hr>';
  7. //输出:Welcome to Beijing!
  8. //Welcome to
  9. //移除字符串右侧的换行符(\n):
  10. $user1 = "Welcome to Beijing!\n\n";
  11. echo $user1;
  12. echo chop($user1);
  13. //输出:Welcome to Beijing! Welcome to Beijing!

convert_uudecode()字符串函数

convert_uudecode() 函数对 uuencode 编码的字符串进行解码。
该函数常与 convert_uuencode() 函数一起使用。

  1. <?php
  2. $str = "Hello world!";
  3. // 对字符串进行编码
  4. $encodeString = convert_uuencode($str);
  5. echo $encodeString . "<br>";
  6. // 对字符串进行解码
  7. $decodeString = convert_uudecode($encodeString);
  8. echo $decodeString;
  9. ?>

字符串解码图示:
字符串进行解码

lcfirst()字符串函数

lcfirst() 函数把字符串中的首字符转换为小写

  1. <?php
  2. //把 "Welcome" 的首字符转换为小写
  3. echo lcfirst("Welcome to Beijing!"
  4. //输出:welcome to Beijing!

parse_str()字符串函数

lcfirst() 函数把查询字符串解析到变量中

  1. <?php
  2. //parse_str 函数把查询字符串解析到变量中
  3. parse_str("name=Mayun&age=56",$user);
  4. print_r($user);
  5. //输出:Array ( [name] => Mayun [age] => 56 )

更多相关文章

  1. 20个PHP字符串函数实例
  2. PHP字符串常用函数
  3. 不少于20个字符串函数练习
  4. PHP基础知识:数组相关函数和操作
  5. 初探jQuery($(),attr(),css(),val(),html(),text(),each())
  6. 指向函数指针数组的指针
  7. 函数的定义和调用,函数的参数,函数的返回值,匿名函数(闭包)的申明和调
  8. PHP常用的数组函数
  9. 数组函数练习

随机推荐

  1. Android:ImageView如何显示网络图片
  2. 实现ListView的item逐个飞入效果——Layo
  3. button imageButton 背景透明
  4. android:imeOptions
  5. Android短信数据库简析
  6. linux eclipse中运行android AVD 错误
  7. 记录EditText的输入属性InputType以及ime
  8. Android 3.0 r1 API中文文档(108) —— E
  9. Kotlin log 工具类
  10. android简单的乘法运算