In the previous article, we learned how to delete backslashes. If necessary, please read "How to delete backslashes in php". This time we will introduce to you the method of finding the first occurrence of a string in another string. You can refer to it if you need it.
In PHP, there is a function that can find the first occurrence of a string in another string. Today we will introduce this function. However, there are two such functions, one is very sensitive to the case of characters, and the other is not sensitive to the case of characters. First, let's introduce the functions that are insensitive to the case of characters.
Let’s look at a little chestnut first.
<?php $str = stripos("When you stare at the abyss, the Abyss is staring at you.","Abyss"); echo($str); ?>
The result of this example is
In order to prevent it from matching "Abyss
" instead of " abyss
”, let’s count it ourselves. Start counting from 0. After counting, we find that the 22nd number is the first letter of "abyss", "a
". It seems that this function really matches the first occurrence of a string in another string, and is not case-sensitive.
Let us observe this function ourselves.
stripos() function finds the first occurrence of a string within another string (case-insensitive).
Come to the syntax of Kangkang function.
stripos(被搜索的字符串,要查找的字符,开始搜索的位置)
After we know the syntax of this function, let’s talk about something we must know, that is the return value of this function.
Returns the position of the first occurrence of a string in another string, or FALSE
if the string is not found. What's more important is that the string position starts from 0, not from 1
.
We have finished introducing this function, let’s take a look at the case-sensitive function.
Let’s look at a small example. What will be the result of the same string and different functions?
<?php $str = strpos("When you stare at the abyss, the Abyss is staring at you.","Abyss"); echo($str); ?>
This result is
The result is different. We don’t need to count the results one by one this time. According to the previous function From my experience, this is definitely "Abyss", not "abyss".
Let’s take a closer look at this function.
strpos(被搜索的字符串,要查找的字符,开始搜索的位置)
The syntax format and return value of this function are the same as the previous function. The only difference is that this function is case-sensitive, while the above function is not case-sensitive.
That’s all. If you want to know anything else, you can click here. → →php video tutorial
The above is the detailed content of How to know the first occurrence of a string in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

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.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
