1// strip tags to avoid breaking any html
2$string = strip_tags($string);
3if (strlen($string) > 500) {
4
5 // truncate string
6 $stringCut = substr($string, 0, 500);
7 $endPoint = strrpos($stringCut, ' ');
8
9 //if the string doesn't contain any space then it will cut without word basis.
10 $string = $endPoint? substr($stringCut, 0, $endPoint) : substr($stringCut, 0);
11 $string .= '... <a href="/this/story">Read More</a>';
12}
13echo $string;