Html Karakter Sınırlandırma

$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('À'=>'&Agrave;','à'=>'&agrave;','Á'=>'&Aacute;','á'=>'&aacute;','Â'=>'&Acirc;','â'=>'&acirc;',
 'Ã'=>'&Atilde;','ã'=>'&atilde;','Ä'=>'&Auml;','ä'=>'&auml;','Å'=>'&Aring;','å'=>'&aring;','Æ'=>'&AElig;','æ'=>'&aelig;',
 'Ç'=>'&Ccedil;','ç'=>'&ccedil;','?'=>'&ETH;','?'=>'&eth;','È'=>'&Egrave;','è'=>'&egrave;','É'=>'&Eacute;','é'=>'&eacute;',
 'Ê'=>'&Ecirc;','ê'=>'&ecirc;','Ë'=>'&Euml;','ë'=>'&euml;','Ì'=>'&Igrave;','ì'=>'&igrave;','Í'=>'&Iacute;','í'=>'&iacute;',
 'Î'=>'&Icirc;','î'=>'&icirc;','Ï'=>'&Iuml;','ï'=>'&iuml;','Ñ'=>'&Ntilde;','ñ'=>'&ntilde;','Ò'=>'&Ograve;','ò'=>'&ograve;',
 'Ó'=>'&Oacute;','ó'=>'&oacute;','Ô'=>'&Ocirc;','ô'=>'&ocirc;','Õ'=>'&Otilde;','õ'=>'&otilde;','Ö'=>'&Ouml;','ö'=>'&ouml;',
 'Ø'=>'&Oslash;','ø'=>'&oslash;','Œ'=>'&OElig;','œ'=>'&oelig;','ß'=>'&szlig;','?'=>'&THORN;','?'=>'&thorn;','Ù'=>'&Ugrave;',
 'ù'=>'&ugrave;','Ú'=>'&Uacute;','ú'=>'&uacute;','Û'=>'&Ucirc;','û'=>'&ucirc;','Ü'=>'&Uuml;','ü'=>'&uuml;','?'=>'&Yacute;',
 '?'=>'&yacute;','Ÿ'=>'&Yuml;','ÿ'=>'&yuml;');
 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;
 }
}

Sizin Değerli Görüşlerinize İhtiyacımız Var.