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在windows系統下無法使用mb_send_mail寄信?

php在windows系統下...

首先,mbsendmail是php所提供可用來發送編碼的郵件。 一般來說會導致無法發送郵件大部分原因...

分享 斜槓青年正夯,什麼都會才是王道?他舉賈伯斯、巴菲特為例,勸你萬萬不可跨領域-風傳媒

分享 斜槓青年正夯,什麼都會...

巴菲特:「了解自己的能力圈,待在裡面。這個圈圈到底有多大其實無關緊要。知道圈圈的邊線究竟在哪則非常重...

修改apache設定

修改apache設定

pexelsphotolock5 進入apache資料夾,找到conf資料夾(預設是C:\AppSe...

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