PHP String Exercises: Select first 5 words from the specified string
PHP String: Exercise-24 with Solution
Write a PHP script to select first 5 words from the following string.
Sample String : 'The quick brown fox jumps over the lazy dog'
<?php $my_string = 'The quick brown fox jumps over the lazy dog'; echo implode(' ', array_slice(explode(' ', $my_string), 0, 5))."\n"; ?>
The quick brown fox jumps
PHP Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?