How to limit text length in php and provide ‘Read more’ link

0

If you have set your php site to display post excerpts on the front or home page, you will want visitors to click on the title or a link to encourage them to continue reading your post or article, right? php makes this technique easy, and customizable.

PHP Code

<?php
   $string = $profileinfo['description'];
   if (strlen($string) > 150) {
       $stringCut = substr($string, 0, 150);
       $endPoint = strrpos($stringCut, ' ');
       $string = $endPoint? substr($stringCut, 0, $endPoint):substr($stringCut, 0);
       $string .= '... <a style="cursor: pointer;" href="" >Read More</a>';
   }
   echo $string;
?>