Funkcija substr ce odrezati rec tacno na toliko karaktera koliko odredis ukljucujuci i html.
Za da ne bi rec bila odrezana na pola recimo nekiTe... ja ovu svrhu ja koristim sledecu funkciku, koja dopusta da se rec zavrsi.
Code:
function truncate($text, $len = 120) {
if(empty($text)) {
return "";
}
if(strlen($text)<$len) {
return $text;
}
return preg_match("/(.{1,$len})\s./ms", $text, $match) ? $match[1] ."..." : substr($text, 0, $len)."...";
}
Nacin upotrebe: echo truncate($text, 100);// 100 je broj karaktera
Uz ovu funkciju mozes koristiti: nl2br, str_replace, strip_tags ....