登录  /  注册
博主信息
博文 46
粉丝 0
评论 0
访问量 37162
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
20个基础函数的练习
lus菜
原创
650人浏览过

函数样式代码:

  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;

效果预览 :

批改老师:天蓬老师天蓬老师

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学