String's strpos function in PHP

String's strpos function in PHP


Posted in : PHP Posted on : January 7, 2011 at 6:05 PM Comments : [ 0 ]

This section contains the detail about the String's strpos function in PHP.

String's strpos function in PHP

Sometimes we need to find the position of a sub string or character in string.

The syntax of the strpos is given below :

strpos(string in which you search, sub string/character)

The strpos returns the position of the first match and if no match is found, it will return FALSE.

Example :

<?php
echo strpos("Devmanuals","m");
?>

Output :

3

As you can see output is not 4 instead of 3, because the counting in string starts from 0, not from1.

Another Example :

<?php
$alphaString = "abcdefghijklmnopqrstuvxyz"; // a-z alphabets
$kPos = strpos($alphaString, "k");
echo "The position of k in our string is $kPos";
?>

Output :

The position of k in our string is 10.

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics