johnsmith153 Posted October 3, 2008 Share Posted October 3, 2008 Very Simple. (well should be!) $string = "Hello How Are You Today?" I want to return: (1) Last word in string. ("Today?") (2) Last but one word in string. ("You") (3) Last but two word in string. ("Are") (4) count how many words in string (above obviously 5) Link to comment https://forums.phpfreaks.com/topic/126832-simple-string-question/ Share on other sites More sharing options...
JasonLewis Posted October 3, 2008 Share Posted October 3, 2008 <?php $string = "Hello How Are You Today?"; $array = explode(" ", $string); $array = array_splice($array, -3); $words = str_word_count($string, 0); echo "<pre>", print_r($array), "</pre><br />Words: ".$words; ?> Link to comment https://forums.phpfreaks.com/topic/126832-simple-string-question/#findComment-656037 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.