limit text length in php and provide ‘Read more’ link Ask Question

<?php
$string = “OUR RESOURCE CENTRE
Get free access to Jamboree’s rich resource pool of preparation tips, mock tests,
admission information & much moreddd ddOUR RESOURCE CENTRE
Get free access to Jamboree’s rich resource pool of preparation tips, mock tests,
admission information & much moreOUR RESOURCE CENTRE
Get free access to Jamboree’s rich resource pool of preparation tips, mock tests,
admission information & much moreOUR RESOURCE CENTRE
Get free access to Jamboree’s rich resource pool of preparation tips, mock tests,
admission information & much moreOUR RESOURCE CENTRE
Get free access to Jamboree’s rich resource pool of preparation tips, mock tests,
admission information & much moreOUR RESOURCE CENTRE
Get free access to Jamboree’s rich resource pool of preparation tips, mock tests,
admission information & much more”;

$string = strip_tags($string);
if (strlen($string) > 500) {

// truncate string
$stringCut = substr($string, 0, 500);
$endPoint = strrpos($stringCut, ‘ ‘);

//if the string doesn’t contain any space then it will cut without word basis.
$string = $endPoint? substr($stringCut, 0, $endPoint):substr($stringCut, 0);
$string .= ‘… <a href=”/this/story”>Read More</a>’;
}
echo $string;

?>