Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  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, '...'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement