29 Eylül 2021 Çarşamba

Php ile Uzun Bir Metni Belirlediğiniz Karakter Sayısı Kadar Kısaltma Fonksiyonu

Metin kısaltma fonksiyonumuzu aşağıda görebilirsiniz.

function kisalt($kelime, $str = 200)
{
    $kelime=strip_tags($kelime);  
if (strlen($kelime) > $str)
  {
	 if (function_exists("mb_substr")) $kelime = mb_substr($kelime, 0, $str, "UTF-8").'...';
	 else $kelime = substr($kelime, 0, $str).'...';
  }
  return $kelime;
}  	

Kullanımı aşağıdadır.

$cumle="Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 
when an unknown printer took a galley of type and scrambled it to make a type specimen book.";

echo kisalt($cumle,80);

Ekran çıktısı aşağıdadır.

// Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem...

Hiç yorum yok:

Yorum Gönder