- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP – Find the last occurrence of a needle within a haystack using the iconv_strrpos() function
In PHP, the iconv_strrpos() function is used to findsthe last occurrence of a needle within a haystack. Or, we can say that the iconv_strrpos() function returns the last character number from the haystack.
string iconv_strrpos(string $haystack, str $needle, str $encoding)
iconv_strrpos() accepts three parameters: $haystack, $needle and $encoding.
$haystack− It denotes the whole string.
$needle− The $needle parameter is used to search the substring from the given whole string.
$encoding− if the $encoding parameter is absent or null, then the string will assume that it may be encoded in iconv.internal_encoding.
iconv_strpos() returns the numeric position of the given first occurrence of the needle from the haystack. If the needle is not found, then the function will return False.
Note: From PHP 8.0 version, encoding is nullable and from PHP 7.1, iconv_strpos() function support for the negative offsets has been added.
<?php # UTF-8 string $int = iconv_strrpos("hello world!","d", "UTF-8"); // It will returns the number of character var_dump($int); ?>
- PHP – iconv_strpos() function – Find the position of the first occurrence of a needle in a haystack
- Get the last occurrence of a substring within a string in Arduino
- PHP – Retrieve internal configuration variables of iconv extension using iconv_get_encoding() function
- How to find the last occurrence of an element in a Java List?
- Get the first occurrence of a substring within a string in Arduino
- PHP – Convert a string to a requested character encoding using iconv()
- Get the substring before the last occurrence of a separator in Java
- Finding the last occurrence of a character in a String in Java
- How to find the index of the last occurrence of repeated values in a vector in R?
- PHP program to find the sum of odd numbers within a given range
- How to find index of last occurrence of a substring in a string in Python?
- How to get everything before the last occurrence of a character in MySQL?
- Search for an element matching the conditions and return the zero-based index of the last occurrence within the entire List in C#
- How to replace the last occurrence of an expression in a string in Python?
- Last occurrence of some element in a list in Python