Home >Backend Development >PHP Problem >What is the string query function in php
php string query function is: 1. stripos() function, which can find the first occurrence position of the specified character; 2. strpos() function, which can find the first occurrence position of the specified character; 3. strripos() Function that can find the position where the specified character last appeared; 4. strrpos() function.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
String in php Query function
#1, stripos() function
stripos() is used to find the first occurrence of a certain part of a string in a string ( not case sensitive).
<?php $findme = 'c'; $mystring1 = 'xyz'; $mystring2 = 'ABC'; $pos1 = stripos($mystring1, $findme); $pos2 = stripos($mystring2, $findme); var_dump($pos1); var_dump($pos2); ?>
2. strpos() function
strpos() is used to find the first occurrence of a string (case sensitive ).
<?php $findme = 'c'; $findme1 = 'C'; $mystring = 'ABCabc'; $pos1 = strpos($mystring, $findme); $pos2 = strpos($mystring, $findme1); var_dump($pos1); var_dump($pos2); ?>
3. strripos() function
strripos() is used to calculate the last time the specified string is in the target string The position in which it appears (case insensitive).
<?php $findme = 'c'; $findme1 = 'C'; $mystring = 'ABCabcabcABC'; $pos1 = strripos($mystring, $findme); $pos2 = strripos($mystring, $findme1); var_dump($pos1); var_dump($pos2); ?>
4. strrpos() function
strrpos() is used to calculate the last time the specified string is in the target string Where it appears
<?php $findme = 'c'; $findme1 = 'C'; $mystring = 'ABCabcabcABC'; $pos1 = strrpos($mystring, $findme); $pos2 = strrpos($mystring, $findme1); $pos3 = strrpos($mystring, $findme1,-5); var_dump($pos1); var_dump($pos2); var_dump($pos3); ?>
Recommended study: "PHP Video Tutorial"
The above is the detailed content of What is the string query function in php. For more information, please follow other related articles on the PHP Chinese website!