So, lets say I have a $somestring
thats holds the value "main/physician/physician_view".
I want to grab just "physician_view". I want it to also work if the passed string was "main/physician_view" or "site/main/physician/physician_view".
Hopefully my question makes sense. Any help would be appreciated!
The strlen() is a built-in function in PHP which returns the length of a given string. It takes a string as a parameter and returns its length. It calculates the length of the string including all the whitespaces and special characters.
or: $text = end((explode('_', '233718_This_is_a_string', 2))); By specifying 2 for the limit parameter in explode() , it returns array with 2 maximum elements separated by the string delimiter. Returning 2nd element ( [1] ), will give the rest of string.
Use the PHP substr() function to extract a substring from a string. Use the negative offset to extract a substring from the end of the string. The last character in the input string has an index of -1 . Use the negative length to omit a length number of characters in the returned substring.
strrpos() Function: This inbuilt function in PHP is used to find the last position of string in original or in another string. It returns the integer value corresponding to position of last occurrence of the string, also it treats uppercase and lowercase characters uniquely.
You can use strrpos()
to find the last occurence of one string in another:
substr($somestring, strrpos($somestring, '/') + 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With