Home  >  Article  >  Backend Development  >  What is the string query function in php

What is the string query function in php

青灯夜游
青灯夜游Original
2022-02-10 16:38:303078browse

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.

What is the string query function in php

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 = &#39;c&#39;;
$mystring1 = &#39;xyz&#39;;
$mystring2 = &#39;ABC&#39;;
$pos1 = stripos($mystring1, $findme);
$pos2 = stripos($mystring2, $findme);
var_dump($pos1);
var_dump($pos2);
?>

What is the string query function in php

2. strpos() function

strpos() is used to find the first occurrence of a string (case sensitive ).

<?php
$findme = &#39;c&#39;;
$findme1 = &#39;C&#39;;
$mystring = &#39;ABCabc&#39;;
$pos1 = strpos($mystring, $findme);
$pos2 = strpos($mystring, $findme1);
var_dump($pos1);
var_dump($pos2);
?>

What is the string query function in php

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 = &#39;c&#39;;
$findme1 = &#39;C&#39;;
$mystring = &#39;ABCabcabcABC&#39;;
$pos1 = strripos($mystring, $findme);
$pos2 = strripos($mystring, $findme1);
var_dump($pos1);
var_dump($pos2);
?>

What is the string query function in php

4. strrpos() function

strrpos() is used to calculate the last time the specified string is in the target string Where it appears

<?php
$findme = &#39;c&#39;;
$findme1 = &#39;C&#39;;
$mystring = &#39;ABCabcabcABC&#39;;
$pos1 = strrpos($mystring, $findme);
$pos2 = strrpos($mystring, $findme1);
$pos3 = strrpos($mystring, $findme1,-5);
var_dump($pos1);
var_dump($pos2);
var_dump($pos3);
?>

What is the string query function in php

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!

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