简体   繁体   中英

custom database query using php mysql

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

假设“详细信息”是您表“文章”中的一列

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; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM