久久久久久久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)
主站蜘蛛池模板: www.youjizz.com日韩 | 欧美日韩一区在线播放 | 成人免费视频在线观看 | 亚洲午夜三级 | 古装人性做爰av网站 | h视频在线免费 | 羞羞视频免费观看 | 成人精品在线观看 | 久久精品国产精品青草 | 天天看天天摸天天操 | 亚洲欧美网站 | 精品一区二区免费视频 | 看羞羞视频 | a欧美| 毛片一级网站 | 免费国产一区二区视频 | 久久亚洲视频网 | 尹人av| 日韩国产免费观看 | av网站观看| 久久久久久久电影 | 九一在线观看 | 国产精品亚洲精品日韩已方 | 中文字幕一区二区在线观看 | 欧美综合在线视频 | 91一区二区三区 | 午夜免费在线观看 | 青青久久久 | www视频在线观看 | 国产精品区一区二区三区 | 艹逼网 | 中文字幕一区二区三区四区 | 久久久免费观看视频 | 99国产精品视频免费观看一公开 | 一区二区三区在线免费观看 | 夜夜操操操| 欧美福利影院 | 欧美极品在线播放 | 超碰精品在线观看 | 精品国产一区二区在线 | 亚洲激情第一页 |