欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP在字符斷點(diǎn)處截?cái)辔淖值膶?shí)現(xiàn)代碼

 更新時(shí)間:2011年04月21日 22:54:34   作者:  
所謂斷字 (word break),即一個(gè)單詞可在轉(zhuǎn)行時(shí)斷開的地方。這一函數(shù)將在斷字處截?cái)嘧址?/div>
復(fù)制代碼 代碼如下:

//所謂斷字 (word break),即一個(gè)單詞可在轉(zhuǎn)行時(shí)斷開的地方。這一函數(shù)將在斷字處截?cái)嘧址?
// Please acknowledge use of this code by including this header.
function myTruncate($string, $limit, $break=".", $pad="...") {
// return with no change if string is shorter than $limit
if(strlen($string) <= $limit)
return $string;
// is $break present between $limit and the end of the string?
if(false !== ($breakpoint = strpos($string, $break, $limit))) {
if($breakpoint < strlen($string) - 1) {
$string = substr($string, 0, $breakpoint) . $pad;
}
}
return $string;
}
/***** Example ****/
$short_string=myTruncate($long_string, 100, ' ');

相關(guān)文章

最新評論