タイトルにあるように、単語やHTMLタグを壊さずに文字列を切りたいので、htmlタグの問題を解決するこの関数を見つけました(自分で少し変更しました)
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);
}
}
しかし、それでも私が起こりたくない単語を半分の文にカットします、これをどのようにソートするかについてのアイデアはありますか?
いつものように、どんな助けでもありがたいです、そして前もって感謝します。