Wednesday, September 26, 2012

การแก้ปัญหา PHP ตัดข้อความด้วย substr แล้วเป็น สี่เหลี่ยม

พอดีได้ไปดู code cms หลายๆ ตัวว่าเข้ามีวิธีการยังไงในการตัดข้อความไม่ให้แสดงสี่เหลียมต่อท้าย
และได้พบคำสั่ง mb_substr รูปแบบการใช้งานคือ
mb_substr(string $str ,int $start[, int $length[, string $encoding]])

การใช้งาน
Code

<?
$massage = 'หลายๆตัวว่าเข้ามีวิธีการยังไงในการตัดข้อความไม่ให้แสดงสี่เหลียมต่อท้าย';
mb_substr('$massag',0,15,'UTF-8');
?>

mb_substr

(PHP 4 >= 4.0.6, PHP 5)
mb_substr — Get part of string

reject note Description

string mb_substr ( string $str , int $start [, int $length [, string $encoding ]] )
Performs a multi-byte safe substr() operation based on number of characters. Position is counted from the beginning of str. First character's position is 0. Second character position is 1, and so on.

reject note Parameters

str
The string to extract the substring from.
start
Position of first character to use from str.
length
Maximum number of characters to use from str.
encoding
The encoding parameter is the character encoding. If it is omitted, the internal character encoding value will be used.

reject note Return Values

mb_substr() returns the portion of str specified by the start and length parameters.

reject note See Also


No comments:

Post a Comment