字符串处理
1.在 PHP 中,只有一个字符串运算符,就是并置运算符 .,用于把两个字符串值连接起来。
<?php
$str1="hello";
$str2="world";
echo $str1." ".$str2;
echo $str1.$str2;
?>
2.strlen() 内置字符串函数
<?php
$str1="hello";
$str2="world";
$str3=$str1." ".$str2;
echo strlen($str3);
?>
3.strrev() 反转字符串
<?php
echo strrev("hello");
?>
4.strtoupper() strtolower()将字符串更改为大写/小写
<?php
$str="Hello World";
echo strtoupper($str);
echo strtolower($str);
?>
5.strpos( ,)在字符串中查找字符或字符串
<?php
$str="hello world";
echo strpos($str,'world');
?>
6.str_replace( 被替换,替换, 替换源 )
<?php
echo str_replace("world", "Kitty", "hello world!");
?>
评论