Skip to navigation
How to trim text with php by letter and break by the last word
22.03.16
function trim_text($input, $length, $ellipses = true, $strip_html = true) { if ($strip_html): $input = strip_tags($input); endif; if (strlen($input) <= $length): return $input; endif; $last_space = strrpos(substr($input, 0, $length), ' '); $trimmed_text = substr($input, 0, $last_space); if ($ellipses): $trimmed_text .= '...'; endif; return $trimmed_text; }
http://www.ebrueggeman.com/blog/abbreviate-text-without-cutting-words-in-half
Reply
Anonymous
Information Epoch 1781571993
Save trees.
Home
Notebook
Contact us