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

WordPress如何關閉迴響留言功能?

WordPress如何關閉迴...

其實WordPress本身的留言迴響功能還蠻健全的。 包括可以設定關鍵字黑名單或者是IP黑名單,強制...

使用jQuery阻止input直接按Enter就送出表單

使用jQuery阻止inpu...

使用表單是傳送資料裡經常會用到的方式。 這時當使用者輸入表單後習慣上按下Enter,則會將表單內容送...

設置屬性 PHP PDO setAttribute

設置屬性 PHP PDO s...

PDO::ATTRCASE:強制列名為指定的大小寫。 PDO::CASELOWER:強制列名小寫。 ...

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