字符串操作
- 拼接
- 截取
- 长度
- 相等
- 包含
- 替换
- 去除开头末尾字符串
<?php
$mail = "zw".((string)22)."@gmail.com";
echo $mail, " length:", strlen($mail), "\n";
$first_point = strpos($mail, '@', 1);
$name = substr($mail, 0, $first_point);
if ($name == 'zw22') {
echo $name, "\n";
}
if (strpos($mail, 'gmail') !== false) {
echo "exist";
}
echo $first_point, ":", $name, "\n";
echo 'server', ":", substr($mail, $first_point + 1, strlen($mail)), "\n";
$email = " ".$mail." \r\n\t";
echo trim($email), "\n";
$bodytag = str_replace("%body%", "black", "<body text='%body%'>");
echo $bodytag;
<h3 id="explode">字符串分割</h3>
php > $result = explode(';','1;2;test');
php > var_dump($result);
array(3) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(4) "test"
}
<h3 id="implode">字符串拼接</h3>
php > $arry = array("1","haha","test");
php > $result= implode(';',$arry);
php > var_dump($result);
string(11) "1;haha;test"