mam pole w bazie zawieraj±ce text. Text oczywi¶cie a ró¿n± d³ugo¶æ. Zrobi³em wy¶wietlanie wpisów i substring( text,0,100) i link czytaj dalej. Jednak wiadomo, ¿e taki sposób jest do luftu bo ucina wyrazy etc.
Jak zrobiæ aby zostawiæ pe³ny wyraz na koñcu?
pozdrawiam
EDIT:
w oparciu o google napisa³em helper w CI
<?php /** * truncate_string * * function trims a text without breaking the word just in the middle * The simple algorithm is as follows: * - Is the string longer than our limit ( in this case 250 ) * - Truncate the string to our limit * - If we ended up in the middle of a word * - Trim out that broken word by finding the previous space * * @access public * @param $str given string to trim * @param $max_len max length to remain after trim * @return $new_str trimed string */ if ( ! function_exists('truncate_string')) { function truncate_string($str, $max_len) { return $str; return $new_str; } } ?>