PHP Help need to limit the body text?

Randall

New member
ok let say i do something like this

$body = $row['body'];
and lets say i wanna limit the text by 150 and add the ... after the $body how would i do that ? many thanks
 
if ( strlen( $body ) > 150 ) $body = substr( $body, 0, 147 ) . '& hellip;';

Remove the space after the ampersand (&). Alternatively, use three dots instead.

You should take into account that if a string is more than 150 but less than 154 characters long, it makes little sense to cut off those last three characters only to replace them with ..., that's why I cut off at 147. Also, this way you KNOW $body is never going to exceed 150 characters.
 
Back
Top