函数样式代码:

  1. $str = 'title="hello world 123"';
  2. echo "$str<hr>";
  3. // 1. 使用反斜线引用字符串
  4. $test = addslashes($str);
  5. echo "$test<hr>";
  6. // 2. 反引用一个引用字符串 除反斜杠
  7. $test = stripslashes($test);
  8. echo "$test<hr>";
  9. // 3. 将特殊字符转换为 HTML 实体
  10. $test = htmlspecialchars($str);
  11. echo "$test<hr>";
  12. // 4.将特殊的 HTML 实体转换回普通字符
  13. $test = htmlspecialchars_decode($test);
  14. echo " $test<hr>";
  15. // 5. 转义元字符集
  16. $test = quotemeta($str);
  17. echo "$test<hr>";
  18. // 6. 传递给脚本的参数 数组格式输入解析
  19. $g = sscanf('hello world zsh', '%s %s %s', $h1, $w1,$z1);
  20. echo "$g : $h1 $w1 $z1<hr>";
  21. // 7. 随机打乱一个字符串
  22. echo str_shuffle($str);
  23. // 8.返回字符串中单词的使用情况
  24. $test = str_word_count($str);
  25. echo "$test<hr>";
  26. $test = str_word_count($str, 1);
  27. echo print_r($test, true), '<hr>';
  28. $test = str_word_count($str, 2);
  29. echo print_r($test, true), '<hr>';
  30. // 9. 输出或返回一个变量的字符串表示
  31. echo var_export(strcmp('13', 13) === 0, true), '<hr>';
  32. // 10. 字符串长度
  33. $test = strlen($str);
  34. echo "$test<hr>";
  35. // 11. 字符串反转
  36. $test = strrev($str);
  37. echo "$test<hr>";
  38. // 12. 标记分割字符串
  39. $test = strtok('ABCD.EFG', '.');
  40. echo "$test<hr>";
  41. // 13. 字符串转大写
  42. $test = strtoupper($str);
  43. echo "$test<hr>";
  44. // 14. 字符串转小写
  45. $test = strtolower($str);
  46. echo "$test<hr>";
  47. // 15. 转换指定字符到字符
  48. $test = strtr($str, array('world' => 'wyhtn'));
  49. echo "$test<hr>";
  50. // 16. 将字符串的首字母转换为大写
  51. echo ucfirst('hello email password <hr>');
  52. //17. 使一个字符串的第一个字符小写
  53. echo lcfirst("WESUUZ YMYWT MNYSQ!<hr>");
  54. // 将字符串中每个单词的首字母转换为大写
  55. echo ucwords('hello email password <hr>');
  56. // 18. 单词分割子串
  57. $test = wordwrap('hello email password',8, "<hr>");
  58. echo "$test<hr>";
  59. //19. parse_str 将字符串解析成多个变量
  60. parse_str("hello= email & password= 12345",$testw);
  61. print_r($testw);
  62. echo "<hr>";
  63. //20. chop — rtrim()的别名,删除字符串的最后一个字符
  64. $str = "hello email password";;
  65. echo $str . "<hr>";
  66. echo chop($str,"password<hr>");
  67. //21. 使用uuencode编码一个字符串
  68. $bianmazfc = convert_uuencode($str);
  69. echo $bianmazfc . "<br>";
  70. echo "<hr>";
  71. // 解码一个 uuencode 编码的字符串
  72. $bianmazfc = convert_uudecode($bianmazfc);
  73. echo $bianmazfc;

效果预览 :

更多相关文章

  1. php字符串函数解析
  2. KMP算法的JAVA实现
  3. 深入探索Redis的五种基础数据类型
  4. [牛客习题]逆置字符串
  5. 初识 PHP 运行原理及数据类型
  6. [牛课习题]判断字符串是否回文及统计回文
  7. Linux字符的查看及修改
  8. php学习笔记(20个常用的字符串函数)
  9. 字符串函数

随机推荐

  1. go语言如何顺序生成数字
  2. go是什么动态语言?
  3. go是解释型语言还是编译型语言
  4. 有哪些项目是go语言的?
  5. go语言用什么开发工具?
  6. go语言如何设置定时器
  7. go语言有什么优点?
  8. go语言 list用法是什么
  9. go语言中make和new的区别是什么?
  10. 编程语言go是什么