Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

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

by
Category:php
php
How to limit text length in php and provide 'Read more' link

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. You may also like How to read more / hide text using Jquery and PHP and Hide elements using jquery on a condition.

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;
?>

0 Comments


Html code work in comment box


Related Post