Loading...

PHP 字串字數計算並隱藏

Temperature: 0 °C

Mark ChangMark Chang
author_tools


PHP 字串字數計算並隱藏
使用PHP substr函式可以做字串切割,但在遇到中文字時記得使用mb_substr來做編碼,才可避免產生亂碼。

$str = "天地有正氣,雜然賦流形。下則為河嶽,上則為日星。於人曰浩然,沛乎塞蒼冥。";((mb_strlen($str,'utf8')>20) ? mb_substr($str,0,20,'utf8') : $str).' '.((mb_strlen($str,'utf8')>20) ? " ..." : "")


上述結果會呈現如下~

天地有正氣,雜然賦流形。下則為河嶽,上則 ...

總之,老掉牙的函式,只是單純紀錄,填補已經衰弱的腦袋。

 

https://innstory.com/story-PHP_字串字數計算並隱藏-1807
PHP

Prev
 如何將mysql_table_autoincrement重設

Next
改變input_placeholder_字體顏色 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

.htaccess與RewriteEngine一起使用時500內部服務器錯誤

.htaccess與Rewr...

在某些情況下,可能未加載apache中的modrewrite模塊。 這時只需要執行以下指令就可以獲得...

點選檔案下載卻直接執行開啟

點選檔案下載卻直接執行開啟

遇到一個情況。 使用者開啟瀏覽器點選某個連結檔案時,不會執行下載而是直接開啟檔案。 原本如果只是圖片...

CSSobject-fit 屬性用於指定應如何調整 img或video的大小以適合其容器

CSSobject-fit ...

在UI排版時常會遇到一個問題,後台上傳的圖片比例無法符合前台顯示的DIV容器。 以前我比較常用的方式...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format