search
Homephp教程php手册php strstr() strrchr() strpos() strrpos()函数

php strstr() strrchr() strpos() strrpos()函数

Jun 13, 2016 am 10:03 AM
phpstrposstrrposhostfunctionjudgmentcharacteroperateyes

这四个函数是字符操作函数,主要是判断字符出现的次数,有需要的朋友可以参考一下。

 代码如下 复制代码

//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");

?>

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.