I'm a little confused here. I'm creating a weblog and I want to limit the number of characters of an article so when the readers click on 'Read more' or '...', they're able to read the full article. I'm searching and try to understand the codes but I'm soooo confused on where to put the codes. I found this code
// strip tags to avoid breaking any html
$string = strip_tags($string);
if (strlen($string) > 500) {
// truncate string
$stringCut = substr($string, 0, 500);
// make sure it ends in a word so assassinate doesn't become ass...
$string = substr($stringCut, 0, strrpos($stringCut, ' ')).'... <a href="/this/story">Read More</a>';
}
echo $string;
from limit text length in php and provide 'Read more' link. And here's my codes
$articlesql = "SELECT articles.*, categories.category_name, admin.admin_name FROM articles, categories, admin WHERE articles.article_category_id=categories.category_id AND articles.article_admin_id=admin.admin_id";
$articleresult = mysql_query($articlesql);
while($articlerow=mysql_fetch_assoc($articleresult))
echo"
<li>
<span></span>
<div>
<h4><a href='article-single.php?id=".$articlerow['article_id']."' title='view details'>".$articlerow['article_title']."</a></h4>
<span>
Posted in <a href = '#'>".$articlerow['category_name']."</a> by <a href='#'>".$articlerow['admin_name']."</a> on <a href='#'>".$articlerow['article_date']."</a>
</span>
</div>
<a href='article-single.php?id=".$articlerow['article_id']."' title='view details'><img src='images/blog-post-1.jpg' alt=''></a>
<p>".$articlerow['article_content']."</p>
</li>
";
I really need someone to help me. Thank you!