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

PHP查詢陣列中是否存在特定字串in_array() 函數

PHP查詢陣列中是否存在特定...

使用函數inarray() ,適用版本(PHP , PHP 5, PHP , PHP ) 使用方式:...

MySQL:ERROR_1067

MySQL:ERROR_10...

最近安裝了Ubuntu Server .系統。 接著安裝了MySQL 5..的版本。 在時間的預設值...

破版,很醜!!

破版,很醜!!

pexelsphotowrite5 破版......很醜對不對!! 我想這是所有從事網頁設計師的痛~...

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