正如標題所說我想剪一個字符串,不違反任何文字或HTML標籤的任何文字或HTML標籤,現在我發現這個功能,這種種的HTML標籤問題出(由我自己稍微修改)PHP如何切串不破壞
function substrhtml($str,$start,$len){
$str_clean = substr(strip_tags($str),$start,$len);
if(preg_match_all('/\<[^>]+>/is',$str,$matches,PREG_OFFSET_CAPTURE)){
for($i=0;$i<count($matches[0]);$i++){
if($matches[0][$i][1] < $len){
$str_clean = substr($str_clean,0,$matches[0][$i][1]) . $matches[0][$i][0] . substr($str_clean,$matches[0][$i][1]);
}else if(preg_match('/\<[^>]+>$/is',$matches[0][$i][0])){
$str_clean = substr($str_clean,0,$matches[0][$i][1]) . $matches[0][$i][0] . substr($str_clean,$matches[0][$i][1]);
break;
}
}
return $str_clean;
}else{
return substr($str,$start,$len);
}
}
,但它仍然減少了一半中旬句話,我不希望發生的事情,對任何想法如何排序呢?
與往常一樣,任何幫助表示感謝,並提前致謝。
相關:http://stackoverflow.com/questions/4738160/workaround-for-the-990-character-limitation-for-email-mailservers –
試試這個鏈接可能會幫助你... http://stackoverflow.com/a/26098951/3944217 – edCoder