久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

限制 php 中的文本長度并提供“閱讀更多"鏈接

limit text length in php and provide #39;Read more#39; link(限制 php 中的文本長度并提供“閱讀更多鏈接)
本文介紹了限制 php 中的文本長度并提供“閱讀更多"鏈接的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我將文本存儲(chǔ)在 php 變量 $text 中.該文本可以是 100 或 1000 或 10000 個(gè)字.按照目前的實(shí)現(xiàn),我的頁面基于文本進(jìn)行擴(kuò)展,但如果文本太長,頁面看起來很難看.

I have text stored in the php variable $text. This text can be 100 or 1000 or 10000 words. As currently implemented, my page extends based on the text, but if the text is too long the page looks ugly.

我想獲取文本的長度并將字符數(shù)限制為 500,如果文本超過此限制,我想提供一個(gè)鏈接,說明閱讀更多".如果點(diǎn)擊閱讀更多"鏈接,它將顯示一個(gè)彈出窗口,其中包含 $text 中的所有文本.

I want to get the length of the text and limit the number of characters to maybe 500, and if the text exceeds this limit I want to provide a link saying, "Read more." If the "Read More" link is clicked, it will show a pop with all the text in $text.

推薦答案

這是我使用的:

// strip tags to avoid breaking any html
$string = strip_tags($string);
if (strlen($string) > 500) {

    // truncate string
    $stringCut = substr($string, 0, 500);
    $endPoint = strrpos($stringCut, ' ');

    //if the string doesn't contain any space then it will cut without word basis.
    $string = $endPoint? substr($stringCut, 0, $endPoint) : substr($stringCut, 0);
    $string .= '... <a href="/this/story">Read More</a>';
}
echo $string;

您可以進(jìn)一步調(diào)整它,但它可以在生產(chǎn)中完成工作.

You can tweak it further but it gets the job done in production.

這篇關(guān)于限制 php 中的文本長度并提供“閱讀更多"鏈接的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗(yàn)證問題中添加自定義注冊(cè)字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產(chǎn)品中添加一個(gè)將更改價(jià)格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 国产69精品久久99不卡免费版 | 国产精品美女久久久久久免费 | 久久久成人网 | 国产精品美女视频 | 日本特黄a级高清免费大片 成年人黄色小视频 | 看一级毛片| 一区二区亚洲 | 国产精品亚洲欧美日韩一区在线 | 欧美黄在线观看 | 久久免费精品视频 | 久久久精品网 | 欧美在线综合 | 国产精品久久久久一区二区三区 | 在线免费观看黄视频 | 成人a视频 | 亚洲欧美中文日韩在线v日本 | 国产丝袜一区二区三区免费视频 | 草久网| 这里只有精品999 | 免费看91 | 中文字幕在线三区 | 国产成人精品一区二区三区四区 | 波多野结衣二区 | 国产99久久久国产精品 | 黄色片亚洲| 免费一级欧美在线观看视频 | 综合网视频 | 丝袜毛片 | 美女一区 | 国产精品一区二区三区在线 | 国产精品久久久久一区二区三区 | 日韩视频精品在线 | 日本黄色片免费在线观看 | 伊人亚洲 | 久久中文字幕一区 | av喷水| 日韩视频一区二区三区 | 99久久精品一区二区毛片吞精 | 成人午夜视频在线观看 | 日本人爽p大片免费看 | 九一视频在线观看 |