<?php setlocale(LC_ALL, "TURKISH"); header('Content-Type: text/html; charset=utf-8'); mb_language('uni'); mb_internal_encoding('UTF-8'); class kelimeSay{ private $metin; function __construct(){ $this->metin = "Nothing Supplied"; } function enUzun($metin){ try{ if(empty($metin)){ throw new Exception("$this->metin"); } $this->metin = $metin; $metin=str_replace(array(".",",","?","!",":",";"),"",$metin); $say = array_filter(explode(" ",$metin)); $kontrol=0; foreach($say as $s){ $s=str_replace(" ","",$s); if(mb_strlen($s) > $kontrol){ $kontrol =mb_strlen($s); $kelime =$s; } } return array("harf"=>$kontrol,$kelime); } catch(Exception $e){ echo 'Caught exception: ', $e->getMessage(), "\n"; } } } $metin = "Korkma sönmez bu şafaklarda yüzen al sancak."; $obj = new kelimeSay; print_r($obj->enUzun($metin)); ?>
Çıktısı
Array ( [harf] => 10 [0] => şafaklarda )