Jump to content

[SOLVED] truncating after a certain amount of characters


dennismonsewicz

Recommended Posts

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

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.  >_>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.