Jump to content

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


adrianmak
 Share

Recommended Posts


/* 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
Link to comment
Share on other sites

  • 8 months later...

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
 Share

  • Recently Browsing   0 members

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