批改状态:合格
老师批语:
任选不少于20个字符串函数进行练习,从参数,返回值,应用场景上进行分析和记忆, (课堂上讲过的不得再写了)
| 函数 | 描述 |
|---|---|
| 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
返回在指定的字符前添加反斜杠
<?php$str = addcslashes("K009 W998 V555 K664 K338","K");echo($str);?> //输出\K009 W998 V555 \K664 \K338
返回在预定义的字符前添加反斜杠的字符串。
<?php//在每个双引号(")前添加反斜杠:$str = addslashes('Beijing is the "capital" of China');echo($str);echo '<hr>';//输出:Beijing is the \"capital\" of China//向字符串中的预定义字符添加反斜杠:$str = "Who's Bill Gates?";echo $str . " This is not safe in a database query.<br>";echo addslashes($str) . " This is safe in a database query.";//输出:Who's Bill Gates? This is not safe in a database query.//Who\'s Bill Gates? This is safe in a database query.
chop() 函数移除字符串右端的空白字符或其他预定义字符。
<?php//从字符串右端移除字符:$str = "Welcome to Beijing!";;echo $str . "<br>";echo chop($str,"Beijing!");echo'<hr>';//输出:Welcome to Beijing!//Welcome to//移除字符串右侧的换行符(\n):$user1 = "Welcome to Beijing!\n\n";echo $user1;echo chop($user1);//输出:Welcome to Beijing! Welcome to Beijing!
convert_uudecode() 函数对 uuencode 编码的字符串进行解码。
该函数常与 convert_uuencode() 函数一起使用。
<?php$str = "Hello world!";// 对字符串进行编码$encodeString = convert_uuencode($str);echo $encodeString . "<br>";// 对字符串进行解码$decodeString = convert_uudecode($encodeString);echo $decodeString;?>
字符串解码图示:
lcfirst() 函数把字符串中的首字符转换为小写
<?php//把 "Welcome" 的首字符转换为小写echo lcfirst("Welcome to Beijing!"//输出:welcome to Beijing!
lcfirst() 函数把查询字符串解析到变量中
<?php//parse_str 函数把查询字符串解析到变量中parse_str("name=Mayun&age=56",$user);print_r($user);//输出:Array ( [name] => Mayun [age] => 56 )
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号