daniel.s Posted January 15, 2015 Share Posted January 15, 2015 Hello, I'm using a function to limit an entry to a predetermined number of characters. This is what it looks like: <?php // Excerpts a field to $limit length function excerpt($str, $limit = 400, $endstr = '…'){ $str = strip_tags($str); if(strlen($str) <= $limit) return $str; $out = substr($str, 0, $limit); $pos = strrpos($out, " "); if ($pos>0) { $out = substr($out, 0, $pos); } return $out .= $endstr; } ?> It works like a charm but sometimes i want to limit two different fields within the same function: <?php echo excerpt($result->summary. $result->body); ?> This works 'OK' but this way i can't get a space between the summary text and the body text. It's i minor issue but it looks kinda dull. For example: "Hello, this is the summary.And this is the body text." My PHP knowledge is low but my guess is that the problem arises with the "strip_tags" function. Is there any way around this? Thanks for help /Daniel 1 Link to comment Share on other sites More sharing options...
Jan Romero Posted January 15, 2015 Share Posted January 15, 2015 There is no space because you didn’t put one there Why not do $partone . ' ' . $parttwo? Edit: Also, upvote for using a proper ellipse char. 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted January 15, 2015 Share Posted January 15, 2015 //offtopic I always wondered, why there aren't easy shortcuts for all those nice typographical chars on PC. For macs it's nearly faster to typealt + . instead of ". . ." . Link to comment Share on other sites More sharing options...
Jan Romero Posted January 15, 2015 Share Posted January 15, 2015 Behold: http://www.microsoft.com/en-us/download/details.aspx?id=22339 How do you think I use typographic quotes in nearly all my posts Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now