php中字符查找函数|php中字符查找函数

更新时间:2016-11-15    来源:php函数    手机版     字体:

【www.bbyears.com--php函数】

stristr() 函数查找字符串在另一个字符串中第一次出现的位置。

如果成功,则返回字符串的其余部分(从匹配点)。如果没有找到该字符串,则返回 false。

语法
stristr(string,search)
*/
$str="hello world";          //定义字符串
$result=stristr($str,"w");         //执行搜索操作
echo $result;           //输出搜索的结果,将输出"world"

/*

stripos() 函数返回字符串在另一个字符串中第一次出现的位置。

如果没有找到该字符串,则返回 false。

语法
stripos(string,find,start)

*/

$str="hello world";          //定义字符串
$result=stripos($str,"w");         //执行搜索操作
echo $result;           //输出搜索的结果,将输出6

/*
*/
$str="hello world";          //定义字符串
$result=stripos($str,"l");         //执行搜索操作
echo $result;           //输出搜索的结果,将返回2

/*
strspn() 函数返回在字符串中包含的特定字符的数目。

语法
strspn(string,charlist,start,length)
*/

$str="hello world";          //定义字符串
$result=strspn($str,"khlleo");        //搜索符合条件的长度
echo $result;           //输出结果长度数,返回5

/*
*/

$str="hello world! ???";       //定义字符串
echo $str."
";        //输出原字符串
echo convert_cyr_string($str,"w","a");     //输出转换后的字符串"hello world! ?.?"

本文来源:http://www.bbyears.com/jiaocheng/28313.html

猜你感兴趣