PHP: strpos from behind - position of last occurrence in string
Question by Compi | 2016-06-06 at 18:50
I am searching for a PHP function returning the position of the last occurrence of a string in another string.
So, I need something like the function strpos, but it should search beginning from the end of the string instead of beginning at the first character of the string. As an example, when searching for "b" within the string "abcba", I will get the position of the last "b" and not of the first one.
Is there such a function available in PHP? Or do I have to write an own function for that purpose?
Related Topics
PHP: Check Strings with Ctype-Functions for Character Classes
Article | 0 Comments
How to resize Image before Upload in Browser
Tutorial | 13 Comments
JavaScript: Remove last character from string
Tip | 5 Comments
How to Replace multiple Texts at the same Time
Tutorial | 0 Comments
PHP: Remove arbitrary Characters at the Beginning and the End of a String
Tutorial | 0 Comments
PHP: Line break and strpos
Question | 1 Answer
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
In addition to the function strpos(), which counts from the front, there is the function strrpos(), which counts from the back (string-right-position).
In this small example, you can see the difference between both functions:
The function strrpos() searches case-sensitive (the uppercase and lowercase writing of the words makes a difference). If the uppercase and lowercase writing should not make a difference you can use the case insensitive function strripos() instead.
Last update on 2017-12-19 | Created on 2016-06-07