剛才寫了一個(gè)php的函數(shù),,這個(gè)函數(shù)的作用就是解決截取字符串但不分割英文單詞的問(wèn)題,。記錄于此,,明天用,。
<?
function noBreakWord($string, $max){
$testChar = substr($string, $max, 1);
if ($testChar == " ") {
return substr($string, 0, $max);
} else {
while ($testChar<>" "){
$testChar = substr($string, $max, 1);
if ($testChar == " "){
return substr($string, 0, $max);
} else {
$max = $max-1;
}
}
}
}
?>