Copy the Code code as follows:
The so-called hyphenation (word break), a place where a word can be broken when changing careers. This function truncates the string at the hyphenation point.
Please acknowledge use of the this Code by including the 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, ");
The above describes the Photoshop CS2 v9.0 green Chinese version of PHP truncation text at the character breakpoint implementation code, including the Photoshop CS2 v9.0 Green Chinese version of the content, I hope to be interested in PHP tutorial friends helpful.