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.
$myString = 'This is a string';
$words = explode(' ', $myString);
$lastWord = array_pop($words);
Posted by
Snippet Viewed 12677 times.

Share your PHP code snippets:

  • Get some recognition & link back to your site.

 

Submit | Browse

Most Recent php snippets

Most Viewed