You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
855 B

  1. <?php
  2. //去除字符串首尾的空白字符(或者其他字符)
  3. $str=' hello world ';
  4. var_dump(trim($str));
  5. echo '<br>';
  6. //获取字符串长度
  7. $str='hello world';
  8. echo $str.' len:'.strlen($str).'<br>';
  9. //获取中文字符串的长度
  10. $str='你好世界';
  11. $len=mb_strlen($str);
  12. echo $str.' len:'.$len.'<br>';
  13. //自动转义字符串,常用于数据库
  14. $sql="select * from talbe1 where 'name'='邝伟键'";
  15. $str=addslashes($sql);
  16. echo $str.'<br>'; // select * from talbe1 where \'name\'=\'邝伟键\'
  17. //还原转义字符
  18. $str=stripslashes($str);
  19. echo $str.'<br>'; // select * from talbe1 where 'name'='邝伟键'
  20. //分割字符串并转为数组
  21. $str='hello,world,php';
  22. $arr=explode(',',$str);
  23. echo '<pre>';
  24. print_r($arr);
  25. echo '<br>';
  26. ?>