Sologet Forum
How to limit text length in php and provide 'Read more' link - Printable Version

+- Sologet Forum (https://www.sologet.com)
+-- Forum: Programming (https://www.sologet.com/Forum-Programming)
+--- Forum: PHP Programming & Tutorials (https://www.sologet.com/Forum-PHP-Programming-Tutorials)
+--- Thread: How to limit text length in php and provide 'Read more' link (/Thread-How-to-limit-text-length-in-php-and-provide-Read-more-link)



How to limit text length in php and provide 'Read more' link - Kingsolomon - 10-31-2018

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

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



RE: How to limit text length in php and provide 'Read more' link - Shugudun - 04-14-2020

It is a good way to encourage members to click on your link.

https://jiji.ng/igando-ikotun/classes-and-courses/personal-php-and-mysqli-training-5L4GkyIFBUBTNyHokpSlVwXv.html?lid=ixncYtDjxftf5Kdq&cur_pos=6&pos=6&ads_count=7&ads_per_page=7&page=1