Home  >  Article  >  Backend Development  >  How to express text that exceeds a fixed length as "..."_PHP Tutorial

How to express text that exceeds a fixed length as "..."_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:00:27903browse

Once, a former colleague (a young girl) asked me a question: She wanted to display a list of article titles on a web page, but considering that some titles were too long and affected the appearance, she wanted to refer to other websites. The style, replace the text that exceeds the fixed length with ellipsis, but I don’t know how to implement it, so I thought of me (oh, you will only think of me when you need me, ugh...)
After getting the topic, I decided Start with the database and write a query statement to achieve it. The result is as follows:
Description statement:
SELECT (LEFT (original field, number of digits) '...') AS new field
FROM table name WHERE DATALENGTH (Original field)>Number of digits
UNION ALL
SELECT Original field AS New field FROM Table name WHERE DATALENGTH (Original field)<=Number of digits
Later, I considered that the DATALENGTH() function is not supported in ACCESS , so it was changed to LEN(), but in this case, the Chinese characters are also counted as one instead of the original two.
Finally written as:
select top 5 * from(
SELECT id,(LEFT([description],25) '...') AS descriptionx,kind,datetime, description, author, hit FROM [ xjx] WHERE len(description)>25
UNION ALL
SELECT id,description AS descriptionx,kind,datetime, description, author, hit FROM [xjx] WHERE len(description)<=25) TempTable where kind='Event Briefing' order by datetime "


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631235.htmlTechArticleOnce, a former colleague (a young girl) asked me a question: She wanted to create a page on a web page Display a list of article titles, but considering that some titles are too long and affect the appearance, just...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn