$al=new cutHTML;
$al->text="<p><a>Merhaba</a></p>";
$al->lenght="5";
echo $al->write();
//Çıktısı "Merha"
class cutHTML {
public $text="";
public $length="";
public function write(){
$this->text=htmlspecialchars_decode($this->text);
$entities = array('À'=>'À','à'=>'à','Á'=>'Á','á'=>'á','Â'=>'Â','â'=>'â',
'Ã'=>'Ã','ã'=>'ã','Ä'=>'Ä','ä'=>'ä','Å'=>'Å','å'=>'å','Æ'=>'Æ','æ'=>'æ',
'Ç'=>'Ç','ç'=>'ç','?'=>'Ð','?'=>'ð','È'=>'È','è'=>'è','É'=>'É','é'=>'é',
'Ê'=>'Ê','ê'=>'ê','Ë'=>'Ë','ë'=>'ë','Ì'=>'Ì','ì'=>'ì','Í'=>'Í','í'=>'í',
'Î'=>'Î','î'=>'î','Ï'=>'Ï','ï'=>'ï','Ñ'=>'Ñ','ñ'=>'ñ','Ò'=>'Ò','ò'=>'ò',
'Ó'=>'Ó','ó'=>'ó','Ô'=>'Ô','ô'=>'ô','Õ'=>'Õ','õ'=>'õ','Ö'=>'Ö','ö'=>'ö',
'Ø'=>'Ø','ø'=>'ø','Œ'=>'Œ','œ'=>'œ','ß'=>'ß','?'=>'Þ','?'=>'þ','Ù'=>'Ù',
'ù'=>'ù','Ú'=>'Ú','ú'=>'ú','Û'=>'Û','û'=>'û','Ü'=>'Ü','ü'=>'ü','?'=>'Ý',
'?'=>'ý','Ÿ'=>'Ÿ','ÿ'=>'ÿ');
foreach ($entities as $key => $value){$ent[] = $key;$html_ent[] = $value;}
$this->text = str_replace( $html_ent, $ent, $this->text );
$this->text=strip_tags($this->text);
$this->text=substr($this->text, 0, $this->length);
$this->text=htmlspecialchars($this->text);
return $this->text;
}
}