字符串处理

1.在 PHP 中,只有一个字符串运算符,就是并置运算符 .,用于把两个字符串值连接起来。

//“  .  ”字符串连接操作
<?php
 $str1="hello";
 $str2="world";
 echo $str1." ".$str2;
 echo $str1.$str2;
 //将str1和str2拼接起来
?>

2.strlen() 内置字符串函数

//返回字符串的长度
<?php
 $str1="hello";
 $str2="world";
 $str3=$str1." ".$str2;
 echo strlen($str3);
?>

3.strrev() 反转字符串

<?php
 echo strrev("hello");
?>
//输出olleh

4.strtoupper() strtolower()将字符串更改为大写/小写

<?php
 $str="Hello World";
 echo strtoupper($str);//大写
 echo strtolower($str);//小写
?>

5.strpos( ,)在字符串中查找字符或字符串

<?php
 $str="hello world";
 echo strpos($str,'world');
?>
//如果有返回第一个匹配到的字符的位置
//未匹配到返回false
//字符串的第一个位置为0

6.str_replace( 被替换,替换, 替换源 )

<?php
 echo str_replace("world", "Kitty", "hello world!");
?>