In-depth analysis of strpos function in PHP
The content of this article is to share with you an in-depth analysis of the strpos function in PHP. The content is very detailed. Friends in need can refer to it. I hope it can help you.
Overview
strpos
is often used in PHP to determine whether a string exists in another string. This article introduces the strpos
function and its implementation. .
strposApplication
<?php /* strpos示例 */ // test echo 'match:', strpos('xasfsdfbk', 'xasfsdfbk') !== false ? 'true' : 'false', ';', PHP_EOL; echo 'match:', strpos('xasfsdfbk', 'fbk') !== false ? 'true' : 'false', ';', PHP_EOL; echo 'match:', strpos('xasfsdfbk', 'xs') != false ? 'true' : 'false', ';', PHP_EOL; echo 'match:', strpos('xasfsdfbk', 'sfs') !== false ? 'true' : 'false', ';', PHP_EOL; // code strpos('xasfsdfbk', 'sfs');
Warning:strpos series functionstrpos
The function may return a Boolean valueFALSE
, but may also return the equivalent of # A non-Boolean value for ##FALSE. Please read the Boolean Types chapter for more information. The return value of this function should be tested using the
===operator.
Description | Version | |
---|---|---|
Find the first occurrence of a string | PHP 4, PHP 5, PHP 7 | |
Find the first occurrence of a string (not case sensitive) | PHP 5, PHP 7 | |
Calculate the specified character The position of the last occurrence of the string in the target string | PHP 4, PHP 5, PHP 7 | |
Calculates the position of the specified string in the target The position of the last occurrence in a string (case-insensitive) | PHP 5, PHP 7 | |
Find a string that appears in another string The position of the first occurrence in the string | PHP 4 >= 4.0.6, PHP 5, PHP 7 | |
Find the position of the string First appearance | PHP 4, PHP 5, PHP 7 | |
case-ignoring version of strstr() function | PHP 4, PHP 5, PHP 7 | |
Count the number of occurrences of a string | PHP 4, PHP 5, PHP 7 |