I have build a database and tables named news
and articles
.
I have inserted 1000 words of article on my table.
I'm able to query article from database but it shows full article on my browser and now I want to show articles with only 100 words then with a "read more" button.
When read more button will be clicked full article will be shown a another page.
Select substring(detail, 1, 100) from articles
Assuming "detail" is a column in you table "articles"
Try This
$word = strip_tags($word); // strip tags to avoid breaking any html
if (strlen($word) > 100)
{
$wordCut = substr($word, 0, 100); // truncate string
$word = substr($wordCut, 0, strrpos($wordCut, ' ')).'... <a href="/this/story">Read More</a>'; // make sure it ends in a word so assassinate doesn't become ass...
}
echo $word;