Jump to content

any build-in function to, return a string by first number of words


Recommended Posts

Posted

/* Using regular expression */

$firstTwenty = trim(preg_replace('/^\s*((?:\S+\s+){20}).*/', '$1', $inputText));

/* Using split and combine */

$firstTwenty = implode(' ', array_slice(explode(' ', $inputText), 0, 20));

  • Like 2
  • 8 months later...
Posted

I can't remember where and if it is even true at all, but it seems to me I saw some helper functions in PW to do exactly that - summaries limited by words + ellipsis. Does anyone know what I am talking about?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...