Eiolon Posted June 5, 2008 Share Posted June 5, 2008 On my front page, I link to articles. I want to use the beginning part of the article as the link but I need it to cut off after a certain amount of characters. It would then have ... that the visitor could click on to view the entire article. It's actually what PHPFreaks is doing on the main page of their new site. Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/108864-cutting-off-text-after-certain-length/ Share on other sites More sharing options...
jonsjava Posted June 5, 2008 Share Posted June 5, 2008 <?php $content = "On my front page, I link to articles. I want to use the beginning part of the article as the link but I need it to cut off after a certain amount of characters. It would then have ... that the visitor could click on to view the entire article. It's actually what PHPFreaks is doing on the main page of their new site. Thanks for your help."; $maxchars = 50; $content = substr($content, 0, $maxchars); $pos = strrpos($content, " "); if ($pos>0) { $content = substr($content, 0, $pos); } echo $content."...(read more)"; outputs: On my front page, I link to articles. I want to...(read more) Link to comment https://forums.phpfreaks.com/topic/108864-cutting-off-text-after-certain-length/#findComment-558450 Share on other sites More sharing options...
discomatt Posted June 5, 2008 Share Posted June 5, 2008 I personally like to store a 'headline' in a dedicated row... where the author can summarize the article. If the author chooses not to use a headline, the script falls back and uses a mtheod like the above Link to comment https://forums.phpfreaks.com/topic/108864-cutting-off-text-after-certain-length/#findComment-558452 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.