• Home
  • Shell
    • Emacs
    • Perl
    • screen
    • sed
  • Ubuntu
    • VNC
  • Web Development
    • Javascript
    • Joomla
    • MySQL
    • osTicket
  • Windows
    • Gimp

Posts tagged post

Web Dev> Select first n words of a sentence

Jan16
2012
Written by Scott Rowley
$sentence = "This is my sentence, there are many like it but this one is mine. What do you think of it?";
$n = 10; // Customize to however many words you want to actually show
$teaser = implode(' ', array_slice(explode(' ', $sentence), 0, $n));
echo $teaser."…READ MORE

Which should result in:
This is my sentence, there are many like it but…READ MORE

$sentence = "This is my sentence, there are many like it but this one is mine. What do you think of it?";
$n = 10; // Customize to however many words you want to actually show
$teaser = implode(' ', array_slice(explode(' ', $sentence), 0, $n));
echo $teaser."…READ MORE

Which should result in:
This is my sentence, there are many like it but…READ MORE

Posted in PHP, Web Development - Tagged array_slice, customize, echo, explode, implode, n, php, read more, sentence, teaser

Corrections? Questions? Comments?

Find an error?
Everything work out great for you?
Have some feedback?
Like to see something added to the article?

PLEASE leave us a comment after the article and let us know how we are doing, or if something needs corrected, improved or clarified.

Thank you!
- The Management

Advertisement

Sudo Bash
By Geeks - For Geeks

Back to Top