Home >Backend Development >PHP Problem >How to query the position of a certain character in a string in php
php method to query the position of a certain character in a string: use the strpos() function to query, for example [echo strpos("You love php, I love php too!","php");] .
The operating environment of this article: windows10 system, php 7, thinkpad t480 computer.
When we learn PHP, we will definitely come into contact with a large number of strings. So what should we do if we want to find the specific position of a certain character in the string? It's actually very simple, because PHP has already provided us with functions, and we can just use them directly.
Let’s take a look at this function.
The strpos() function can find the specific position where a string appears for the first time in another string. If the string is not found, it returns FALSE.
Then let’s take a look at how this function is used.
For example, if we want to find the first occurrence of "php" in a string, the code is as follows:
<?php echo strpos("You love php, I love php too!","php"); ?>
Recommended learning: php training
The above is the detailed content of How to query the position of a certain character in a string in php. For more information, please follow other related articles on the PHP Chinese website!