Blogger Information
Blog 20
fans 0
comment 1
visits 13092
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php运算符和常用字符串函数
zg的php学习
Original
497 people have browsed it

运算符

  1. //算术运算符
  2. $num1 = 10;
  3. $num2 = 20;
  4. // echo $num1 + $num2; //输出30
  5. // echo $num1 - $num2; //输出-10
  6. // echo $num1 * $num2; //输出200
  7. // echo $num1 / $num2; //输出0.5
  8. echo $num1 % $num2; //输出10
  9. echo '<hr/>';
  10. // 字符串连接符
  11. $str1 = 'hello';
  12. $str2 = 'world';
  13. echo $str1 . ' ' . $str2; //输出hello world
  14. echo '<hr/>';
  15. //赋值运算符
  16. $n = 5;
  17. $m = 6;
  18. // echo $n += $m; //输出11
  19. // echo $n -= $m; //输出-1
  20. // echo $n *= $m; //输出30
  21. // echo $n /= $m; //输出0.83333333333333
  22. // echo $n .= $m; //输出56 ,最后的56是string类型
  23. // var_dump($n .= $m); //string(2) "56"
  24. // echo $n++; //输出5 ,先输出5,再将n+1
  25. // echo ++$n; //输出6 ,先计算n+1,再将结果6赋值给n,最后再输出新的n
  26. // echo $n--; //输出5
  27. echo --$n; //输出4
  28. echo '<hr/>';

字符串常用函数

  1. //字符串查找
  2. $string = 'abcdefg';
  3. $search = 'cDe';
  4. // echo strpos($string, $search); //输出空 ,查找时大小写敏感
  5. // echo stripos($string, $search); //输出2 ,查找时忽略大小写
  6. // echo strstr($string, $search); //输出空 ,查找时大小写敏感
  7. echo stristr($string, $search); //输出cdefg ,查找时忽略大小写
  8. echo '<hr/>';
  9. $string = ' ';
  10. $replace = '&nbsp;';
  11. $search = chr(32);
  12. echo 'aaa' . str_replace($search, $replace, $string) . 'bbb'; //输出aaa bbb
  13. // str_ireplace($search, $replace, $string) //查找时忽略大小写
  14. //字符串截取和替换
  15. echo '<hr/>';
  16. $str = 'hello world';
  17. // echo substr($str,6); //输出world
  18. echo substr_replace($str,'aaa',6); //输出hello aaa
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