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重新命名帶有前綴的session.name

直接在PHP重新命名帶有前綴...

直接在php檔案裡加入以下指令 sessionname(&#;SecurePHPSESSID&#;)...

解決iphone 不能使用colorbox 滑動的方式

解決iphone 不能使用c...

pexelsphotoiphone #cboxLoadedContent, #cboxContent...

php檢查陣列中大於0的值

php檢查陣列中大於0的值

假設有一個陣列$a $a = array(,,,,,,); 取得大於的數值有幾個 $tempa = ...

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