/ Published in: PHP

Cut or trim a string by given word number
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /** * Trim a string to a given number of words * * @param $string * the original string * @param $count * the word count * @param $ellipsis * TRUE to add "..." * or use a string to define other character * @param $node * provide the node and we'll set the $node-> * * @return * trimmed string with ellipsis added if it was truncated */ function word_trim($string, $count, $ellipsis = FALSE){ $string .= $ellipsis; } elseif ($ellipsis){ $string .= '…'; } } return $string; } ?>
URL: http://www.lullabot.com/articles/trim_a_string_to_a_given_word_count
Comments
