1、下面的字符串是5个邮箱地址,要求输出每个邮箱的用户名。
字符串如下:
lili@162.com,tom@163.com,18765231@qq.com,jack@sina.com,wang@162.com
答案:
<?php
$str = "&& 明日编程词典 &&";
$str1 = trim(trim($str,"&&"));
echo "---".$str1."--";
echo strlen($str1);
//rtrim(ltrim($str,"&& ")," &&")
echo "<hr>";
$s="At the beginning of the new year, I wish you a happy New Year";
$s1 = strtolower($s);
echo substr_count($s1,"new year");
echo "<br>";
echo str_ireplace("new year","@",$s);
?>
2、去除字符串“&& 明日编程词典 &&”首尾空格和特殊字符&&,并计算剩下字符串的长度。
在字符串“At the beginning of the new year, I wish you a happy New Year”,检索“new year”出现的次数(不区分大小写),然后把“new year”替换成"@"。
<?php
$str = "&& 明日编程词典 &&";
$str1 = trim(trim($str,"&&"));
echo "---".$str1."--";
echo strlen($str1);
//rtrim(ltrim($str,"&& ")," &&")
echo "<hr>";
$s="At the beginning of the new year, I wish you a happy New Year";
$s1 = strtolower($s);
echo substr_count($s1,"new year");
echo "<br>";
echo str_ireplace("new year","@",$s);
?>
基本的函数,多加练习熟能生巧。