php description limit

Solutions on MaxInterview for php description limit by the best coders in the world

showing results for - "php description limit"
Louisa
27 Mar 2016
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;