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

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

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

問題描述

限時送ChatGPT賬號..

我將文本存儲在 php 變量 $text 中.該文本可以是 100 或 1000 或 10000 個字.按照目前的實現,我的頁面基于文本進行擴展,但如果文本太長,頁面看起來很難看.

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.

我想獲取文本的長度并將字符數限制為 500,如果文本超過此限制,我想提供一個鏈接,說明閱讀更多".如果點擊閱讀更多"鏈接,它將顯示一個彈出窗口,其中包含 $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;

您可以進一步調整它,但它可以在生產中完成工作.

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

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

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

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 久久狠| 老司机精品在线 | 日韩亚洲欧美在线观看 | 国产中文字幕av | 亚洲福利网 | 亚洲一区在线看 | 无套内谢的新婚少妇国语播放 | 久久久久久一区 | 91人人爽| 日韩视频免费大全中文字幕 | 精品一区二区国产 | 国产三级精品视频 | 死神来了4无删减版在线观看 | 成年在线观看 | 六月激情 | 天天操天天插 | 深夜在线视频 | 久久久久久久综合 | 亚洲欧美一区二区三区在线 | 亚洲国产精品久久久久久 | 中文字幕久久久久 | 91爱爱网 | 国产精品一区一区三区 | 五月婷婷色综合 | 日韩黄色录像 | 激情福利视频 | 久久久久久久久国产 | 在线成人免费视频 | 操碰在线视频 | 日韩av在线网站 | 中文字幕2021 | 在线日韩 | 91青青草 | 色黄大色黄女片免费中国 | 国产精品一区二区三区不卡 | 久久精品久久久 | 欧美精品在线观看 | 男女那个视频 | 欧美特黄一级片 | 国产一级网站 | 91久久国产精品 |