Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $str = 'A ju kaskdn kskj pstru askdol l asjndk;llll masd masdmasdoa sd as mmm.';
- // simple, also need with charsLimit
- function trimWords($str, $wordsLimit, $endCharacter) {
- $strPieces = explode(' ', $str);
- $neededPices = array_slice($strPieces, 0, $wordsLimit);
- $result = implode(' ', $neededPices) . $endCharacter;
- return $result;
- }
- var_dump(trimWords($str, 5, '...'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement