Difference Between Strpos and Stripos Function

Introduction

The strpos() function finds the position of a string and the stripos() function is the same as the strpos() function but is used for a case-insensitive search. Both return the position of the first occurrence of a string inside another string.
If the string is not found, this function returns FALSE. The strpos() function is used to find a string position in a string. The strpos() function will return with the position of the first match, not every match in the string.

Syntax

strpos(what to search, what to search for);

strpos(string,find,start)

Example

<?php
echo
strpos("Hello Sharad kumar!","S");
?>

The problem there is that strpos() matches the first "S" it comes across, which will be in "This". Fortunately there is a third parameter to strpos() that allows us to specify where to start from. As the "S" in "This" is at index 2, we just need to specify one place after that (3) as the start position for strpos(), and it will report back the next "S" after it

Output

strpos.jpg

Note: The strpos() function is case-sensitive. Being able to manipulate strings is a valuable skill, especially in PHP. You'll most likely come across a programming problem that requires you to find some data in a string. The beginning of a lot of your string manipulation expertise will begin with the strpos function, which allows you to find data in your string. One of the limitations of strpos is that it only returns the position of the very first match.

Syntax

stripos(string,find,start)

 

Example

<?php

echo Stripos("Hello Sharad kumar!","K");

?>

Output

 stripos.jpg

Note: But stripos() function case-insensitive.


Similar Articles