Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // http://www.geekysolution.com/how-to-select-first-5-words-from-a-string-in-php/
- $my_string = 'geekysolution is an awesome mentor in the whole internet';
- // Break the string into words
- $words = explode(' ', $my_string);
- // Select first five (5) words
- $five_words = array_slice($words,0,5);
- // Combine the five (5) words into string
- $String_of_five_words = implode(' ',$five_words)."\n";
- // Show the string of five words
- echo $String_of_five_words;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement