Blogger Information
Blog 33
fans 0
comment 0
visits 17094
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php字符串函数
lucaslwk
Original
387 people have browsed it

字符串函数

字符串函数

  1. <?php
  2. //substr_count 计算字串出现的次数
  3. echo substr_count('php.cn', 'p') . '<br>';
  4. //结果:2
  5. //str_pad 使用另一个字符串填充字符串为指定长度,默认填充右侧
  6. echo str_pad('php.cn', 10, '=', false) . '<br>';
  7. //结果:====php.cn
  8. echo str_pad('php.cn', 10, '=', STR_PAD_BOTH) . '<br>';
  9. //结果:==php.cn==
  10. //str_repeat 重复一个字符串
  11. echo str_repeat('-*-|', 3) . '<br>';
  12. //结果:-*-|-*-|-*-|
  13. //str_shuffle 随机打乱一个字符串, 可用于生成验证码
  14. echo str_shuffle('abcdefg') . '<br>';
  15. //结果:gebfdac
  16. //strspn 计算长字符串a中从开头连续几个字符都属于短字符串b
  17. echo strspn("php.cn php", "php") . '<br>';
  18. //结果:3
  19. echo strspn("php.cn php", "php", 7, 2) . '<br>';
  20. //结果:2
  21. //strtolower 转化为小写
  22. echo strtolower('PHP') . '<br>';
  23. //结果:php
  24. //strtoupper 转化为大写
  25. echo strtoupper('php') . '<br>';
  26. //结果:PHP
  27. //ucfirst 首字母大写
  28. echo ucfirst('php.cn') . '<br>';
  29. //结果:Php.cn
  30. //htmlspecialchars 将html标签和引号等转换为html实体字符
  31. echo htmlspecialchars("<a href='edit.php?id=1&p=2'>\"编辑\"</a>") . '<br>';
  32. //结果:<a href='edit.php?id=1&p=2'>"编辑"</a>
  33. //htmlspecialchars_decode 将html实体字符转换为html标签和引号等
  34. echo htmlspecialchars_decode("&lt;a href='edit.php?id=1&amp;p=2'&gt;&quot;编辑&quot;&lt;/a&gt;") . '<br>';
  35. //结果:"编辑"
Correcting teacher:PHPzPHPz

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