search
Homephp教程php手册如何在把超过固定长度的文字以"……"表示

有次,有个以前的同事(是个小MM)问我一个问题:她想在一个网页中显示一个文章标题的列表,但是考虑到有的标题太长,影响美观,就想参照别的网站上的样式,把超过固定长度的文字用省略号代替,但是自己又不知道如何实现,所以想到我(唉,需要我的时候才会想到我,呜……)
拿到题目后,我决定从数据库来着手,写查询语句来实现,结果如下:
说明语句:
SELECT (LEFT(原字段,位数) '...') AS 新字段
FROM 表名 WHERE DATALENGTH(原字段)>位数
UNION ALL
SELECT 原字段 AS 新字段 FROM 表名 WHERE DATALENGTH(原字段)后来考虑到ACCESS中不支持DATALENGTH()函数,所以改为LEN(),不过这样的话,中文字也算作一位,而不是原来的两位。
最后写成:
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)

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment