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. Quote Link to comment 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) Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.