PHP

 Home  Computers & Internet  Web Programming PHP
What is PHP?
Echo
Comments
Variables
Constants
Data Types
number_format()
Character Strings
Mathematical Operators
Comparison Operators
Logical Operators
Joining Strings
explode()
implode()
strtolower()
strtoupper()
strlen()
ucfirst()
ucwords()
strrev()
str_replace()
str_repeat()
trim()
strip_tags()
addslashes()
stripslashes()
strpos()
strrpos()
nl2br()
isset()
unset()
empty()
POST
GET
If Statements
If Else Statements
Elseif Statements
Switch Statements
For Loops
While Loops
Do While Loops
Foreach Loops
File Create
File Open
File Read
File Write
File Delete
fgets()
file_get_contents()
Date & Time
$_SERVER
Sessions
Cookies
Arrays

HOW TO USE THE strrpos() FUNCTION IN PHP

The strrpos() function is used to find the last occurrence of a string inside another string. If found, the function returns, as an integer, the position of the last occurrence of that string searched for.

If no strings found, the function returns false. Please bear in mind that the strrpos() function is case sensitive. Also note the characters are counted in a string numerically where the first character is position 0.

The general format is:

strrpos(string to search, string to find, starting position);

string to search - The string to perform the search.
string to find - The string to find.
starting position = Integer. Optional. Indicates position to start search from. If not set, position starts from beginning of string by default.

Example Without The Optional Start Position

$string_to_search="My name is Wendy Moss";
$string_to_find="n";

$position=strrpos($string_to_search,$string_to_find);

echo $position;

The above outputs: 13 as n occurs last at character position 13 (occurs first at position 3).

Example With The Optional Start Position

$string_to_search="My name is Wendy Moss. I am not Selena Smith!";
$string_to_find="n";

$position=strrpos($string_to_search,$string_to_find, 4);

echo $position;

The above outputs: 36 as n is last found at position 36.

See also:

strpos() function


Home | Privacy Policy | Terms Of Use | Contact Us | Work At Home | Online Jobs | Smart Info | Online Jobs | Data Entry Jobs | Paid Surveys | Info | Info | Typing Jobs | Article Archive | Forum Posting Jobs