Blogger Information
Blog 46
fans 0
comment 0
visits 39212
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
20个基础函数的练习
lus菜
Original
688 people have browsed it

函数样式代码:

  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;

效果预览 :

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post