$myString = 'This is a string'; $words = explode(' ', $myString); $lastWord = array_pop($words);
PHP Get the last word in a string
By using PHP's built in explode and array_pop functions, you can get the last word in a string with just two lines of code.
Snippet Viewed 13896 times.
Share your PHP code snippets:
- Get some recognition & a link back to your site.
- Create your own code library.
- Help your fellow developers, as they have helped you.