SHARE
TWEET

Untitled

a guest Apr 18th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $str = 'A ju kaskdn kskj pstru askdol l asjndk;llll masd masdmasdoa sd as mmm.';
  4. // simple, also need with charsLimit
  5. function trimWords($str, $wordsLimit, $endCharacter) {
  6.   $strPieces = explode(' ', $str);
  7.  
  8.   $neededPices = array_slice($strPieces, 0, $wordsLimit);
  9.   $result = implode(' ', $neededPices) . $endCharacter;
  10.  
  11.   return $result;
  12. }
  13.  
  14. var_dump(trimWords($str, 5, '...'));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top