Created
April 19, 2013 18:35
-
-
Save bolstad/5422277 to your computer and use it in GitHub Desktop.
Begränsa strängen till max antal chars men behåll hela ord
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function cutstr($str, $length, $ellipsis='') | |
{ | |
$cut=explode('\n\n',wordwrap($str),$length,'\n\n')); | |
return $cut[0].((strlen($cut)<strlen($str))?$ellipsis:''); | |
} | |
echo cutstr('hej hej, nu ska vi kolla på hur det blir här. kommer det här att bli bra? eller vad säger du ? ', 30,'...'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment