php
//strstr:从左向右查找 返回值:字符串
//strrchr:从右向左查找 返回值:字符串
//strpos:从左向右查找 返回值:整型,假如查找的字符串不存在,则返回空
//strrpos:从右向左查找 返回值:整型
$str="天高任鸟飞,海阔凭鱼跃";//strstr:从左向右查找 strrchr:从右向左查找
echo "原始字符串:".$str." ";
echo "用strstr函数搜索“,”的返回结果:".strstr($str,",")." ";
echo "用strstr函数搜索“鸟飞”的返回结果:".strstr($str,"鸟飞")." ";
$str1="I have a great dream.";
echo "原始字符串:".$str1." ";
echo "用strrchr函数搜索“e”的返回结果:".strrchr($str1,"e")." ";
echo "用strrchr函数搜索“ea”的返回结果:".strrchr($str1,"ve")." ";
$str2="I am an abstract about abroad.";
echo "原始字符串为:".$str2." ";
echo "ab在字符串中的第一次出现位置为:".strpos($str2,"ab")." ";
echo "ab在字符串中的第一次出现位置为:".strpos($str2,"am")." ";
echo "abcd在字符串中第一次出现的位置为:".strpos($str2,"aman")." ";
$str3="I am is wang hui.";
echo "原始字符串为:".$str3." ";
echo "I在字符串中的最后一次出现位置为:".strrpos($str3,"I")." ";
echo "an在字符串中的最后一次出现位置为:".strrpos($str3,"an")." ";
echo "i在字符串中最后一次出现的位置为:".strrpos($str3,"i");
?>
|