Jump to content

[solved] Character Limit When Displaying


Yvil

Recommended Posts

Hey everybody,After a few days of seriously trying I managed to get my own blogging system working, but now there's one problem left:How do I put a character limit to the output content?For example: On my homepage I want to display the last 5 posts, but I don't want them to be their full length, since that would be too long.Here's the used code:

	echo "<h3>Viewing 5 latest posts.</h3>";	$result = mysql_query("SELECT * FROM Blog LIMIT 5 ORDER BY Id DESC");		while($row = mysql_fetch_array($result))		{		echo "<div class=\"blogpost\">";		echo "<h4><a href=\"./index.php?view=post&id=" . $row['Id'] . "\" target=\"_self\">" . $row['Title'] . "</a></h4>";		echo "<h6>Posted by " . $row['Name'] . " on " . $row['Posted'] . " in <a href=\"./index.php?view=cat&cat=" . $row['Category'] . "\" target=\"_self\">" . $row['Category'] . "</a></h6>";		echo "<p>" . $row['Content'] . "</p>";		echo "</div>";

Thanks in advance,YvilEDIT: " . $row['Content'] . " is what I'm trying to put a character limit to.

Link to comment
Share on other sites

Now I'm using this, but it still doesn't work..How should I use the substr?

	echo "<h3>Viewing 5 latest posts.</h3>";	$result = mysql_query("SELECT * FROM Blog LIMIT 5 ORDER BY Id DESC");		while($row = mysql_fetch_array($result))		{		echo "<div class=\"blogpost\">";		echo "<h4><a href=\"./index.php?view=post&id=" . $row['Id'] . "\" target=\"_self\">" . $row['Title'] . "</a></h4>";		echo "<h6>Posted by " . $row['Name'] . " on " . $row['Posted'] . " in <a href=\"./index.php?view=cat&cat=" . $row['Category'] . "\" target=\"_self\">" . $row['Category'] . "</a></h6>";		echo "<p>";		echo substr($row['Content'], 0, [200]);		echo "</p></div>";

EDIT: Nevermind, shouldn't have put square brackets around 200. Thanks Deirdre's Dad, for the fast solution!

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...