dennismonsewicz Posted August 5, 2008 Share Posted August 5, 2008 how would I go about taking text like out of a DB and truncate it after a set amount of characters? After 80 characters i would like to place a "read more" statement. Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 5, 2008 Share Posted August 5, 2008 I just did one of those not too long ago: <script language=\"JScript\"> function showMore(e, text) { e.vTemp = e.innerHTML; e.innerHTML = text + \" <a href='Javascript://' STYLE='font-size:10px' onclick='this.parentElement.innerHTML=this.parentElement.vTemp'>(less)</a>\"; } </script> if (strlen($value) > 80) echo "<b>$field:</b><br><div STYLE=\"margin-left:40px;font-style:italic;width:300px\">". substr($value, 0, 77) ."...<a href=\"Javascript://;\" STYLE=\"font-size:10px\" onclick=\"showMore(this.parentElement, '<i>".preg_replace("[']", "\'", $value)."</i>');\">(more)</a></div>"; else echo "<b>$field:</b><br><div STYLE=\"margin-left:40px\">". $value ."</div><br>"; I think just this part answers your question, though: substr($value, 0, 77); Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 5, 2008 Share Posted August 5, 2008 Assuming $text is your text from the DB: $text = substr($text, 0, 80) . "..."; $text .= sprintf('<a href="articles.php?id=%d">Read More</a>', $id); Assuming articles.php is your Read More page and $id is your text's ID. >_> Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted August 5, 2008 Author Share Posted August 5, 2008 thanks bud! Problem Solv... ed! 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.