imarockstar Posted November 24, 2008 Share Posted November 24, 2008 I am displaying data on my site. (duh) .. and I am limiting the character display to 200 characters. I am using the below code : <?= substr($text,0,200) ?> The above works great. My question is that what if the total number of characters to be displayed is less then 200, at that point I do not need to display a read more link. However if the total number of characters IS over 200 I need to display a (read more) link .. anyone know the best way to do this ? b Link to comment https://forums.phpfreaks.com/topic/134056-limit-characters-based-on-total-number-of-characters/ Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 <?php if(strlen($text) > 200){ print substr($text,0,200); print '<a href="more.php">Read More...</a>'; }else{ print $text; } ?> Link to comment https://forums.phpfreaks.com/topic/134056-limit-characters-based-on-total-number-of-characters/#findComment-697830 Share on other sites More sharing options...
Adam Posted November 24, 2008 Share Posted November 24, 2008 if (strlen($text) < 200) { echo $text; } else { echo sustr($text, 0, 200) . ' ... <a href="readmore.php?id=#">Read more</a>'; } EDIT: rhodesa beat me too it! Link to comment https://forums.phpfreaks.com/topic/134056-limit-characters-based-on-total-number-of-characters/#findComment-697831 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.