Q:

Write a PHP script to select first 5 words from the following string

0

Write a PHP script to select first 5 words from the following string.

Sample String : 'The quick brown fox jumps over the lazy dog'

Pictorial Presentation:

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
$my_string = 'The quick brown fox jumps over the lazy dog';
echo implode(' ', array_slice(explode(' ', $my_string), 0, 5))."\n";
?>

Sample Output:

The quick brown fox jumps

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now