php字符串函数学习之strstr(),字符串strstr_PHP教程

WBOY
Release: 2016-07-13 10:00:07
Original
734 people have browsed it

php字符串函数学习之strstr(),字符串strstr

复制代码 代码如下:
/*
定义和用法
strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。
该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。
语法
string strstr ( string, search)

参数 描述
string 必需。规定被搜索的字符串。
search 必需。规定所搜索的字符串。如果该参数是数字,则搜索匹配数字 ASCII 值的字符

提示和注释
注释:该函数是二进制安全的。
注释:该函数对大小写敏感。如需进行大小写不敏感的搜索,请使用 stristr()。
如果你仅仅想确定 needle 是否存在于 haystack 中,请使用速度更快、耗费内存更少的 strpos() 函数。
*/
$str = "。规定的被搜索的字符串 ";
$s = "的";
echo strstr($str,$s) . "
";
echo mb_strstr($str,$s, 'utf-8') . "
";
echo mb_strstr($str,$s, true, 'utf-8') . "
";
echo mb_strstr($str,$s, false, 'utf-8') . "


";

/*
定义和用法
strrchr() 函数查找字符串在另一个字符串中最后一次出现的位置,并返回从该位置到字符串结尾的所有字符。
如果成失败,否则返回 false。
语法
strrchr(string,char)
参数 描述
string 必需。规定被搜索的字符串。
char 必需。规定要查找的字符。如果该参数是数字,则搜索匹配数字 ASCII 值的字符。
*/
echo strrchr($str,$s) . "
";
echo mb_strrchr($str,$s, 'utf-8') . "
";
echo mb_strrchr($str,$s, true, 'utf-8') . "
";
echo mb_strrchr($str,$s, false, 'utf-8') . "


";

$str = "Hello world!Hello world!";
$s = "world";
echo strrchr($str,$s) . "
";
echo mb_strrchr($str,$s, 'utf-8') . "
";
echo mb_strrchr($str,$s, true, 'utf-8') . "
";
echo mb_strrchr($str,$s, false, 'utf-8') . "


";

/*
定义和用法
strtr() 函数转换字符串中特定的字符。
语法
strtr(string,from,to)
或者
strtr(string,array)
参数 描述
string1 必需。规定要转换的字符串。
from 必需(除非使用数组)。规定要改变的字符。
to 必需(除非使用数组)。规定要改变为的字符。
array 必需(除非使用 from 和 to)。一个数组,其中的键是原始字符,值是目标字符。
说明
如果 from 和 to 的长度不同,则格式化为最短的长度。
*/
echo strtr("Hilla Warld","ia","eo"). "
";
$arr = array("Hello" => "Hi", "world" => "earth");
echo strtr("Hello world",$arr). "


";

echo strtr("如果省略,则使用内部字符编码","内部","外部"). "
";
$arr = array("如果" => "若", "则" => "那么");
echo strtr("如果省略,则使用内部字符编码",$arr). "


";
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/974673.htmlTechArticlephp字符串函数学习之strstr(),字符串strstr 复制代码 代码如下: php /* 定义和用法 strstr() 函数搜索一个字符串在另一个字符串中的第一次出现...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!