Php ile kelime sayacı nasıl yapılır? Turkish Tutorial

in #utopian-io7 years ago

ENGLISH

Hello guys my name is Sinan Karayaman. I have been working on wordpress and other web services for few years now.Now lets begin how to create kelime sayacı step by step.

How to create kelime sayacı?

TÜRKÇE

Merhaba arkadaşlar ben Sinan Karayaman.Bugün sizlere php ile kelime sayacı nasıl oluşturulur onu anlatacağım.Kelime sayacı vereceğiniz metindeki kelimelerin kaç kere kullanıldığını alt alta listeler.

<!DOCTYPE html>
<html>
<head>
    <title>Kelime Saydırma</title>
</head>
<body>

<?php
        /*
        sinan karayaman
        20.12.2017
        */
    function KelimeleriSay($Kelimeler){

        $KelimelerParcala = explode(" ", $Kelimeler);

        $Sonuc = array();
        foreach ($KelimelerParcala as $Kelime) {

            $Say = 0;
            foreach ($KelimelerParcala as $Kontrol) {

                if($Kelime === $Kontrol){

                    $Say++;

                }

            }

            $Sonuc[] = $Kelime." Kelimesi ".$Say." Tane Var";

        }

        $Sonuc = array_unique($Sonuc);
        $Sonuc = implode("<br>", $Sonuc);

        return $Sonuc;

    }

    $Kelimeler = 'kontrol amaçlı ornek metin girdim sinan karayaman ornek dosyaya yazdım programda herhangi bir problem var mı diye kontrol ediyorum sinan karayaman';

    $KelimeleriSaydir = KelimeleriSay($Kelimeler);
    echo $KelimeleriSaydir;
    
?>

</body>
</html>

1.png

*15. Satırda bulunan explode fonksiyonu ile kelimeleri boşluklardan ayırarak array yani dizilere aktarıyoruz.

*18 satırda ise 15. satır daki dizileri foreach yardımı ile döngü içine aktarıyoruz.

*20 .Satırda ise kelimeleri saymak için $Say adında bir değişken aktarıyoruz.

*21. ve 23. Satırda ise, $Kelimelerin tekrar foreach yardımı ile kelime var mı yok mu diye tekrar kontrol ediyor.

*25. satırda ise yukarıdaki şartlar sağlanıyor $Say değişkenini +1 artırıyoruz.

*31. Satırda ise $Sonuc dizisine $Kelimenin kaç kere tekrar edildiğini aktarıyoruz.

*35. Satırda ise $Sonuc dizisinde de tekrar edenleri array_unique fonksiyonun yardımı ile siliyoruz.

*36. Satırda ise implode ile dizileri birleştirip string değere çeviriyoruz.

*38. Satırda ise $Sonuc değişkenini return ettiriyoruz.

2.png

*42. Satırda $Kelimeler değişkenine örnek kelimeler veriyoruz.

*44. Satırda bu kelimeleri 13. satırdaki KelimeleriSay fonksiyonumuza veriyoruz

*45. Satırda KelimeleriSay fonksiyonundan gelen yanıtı ekrana basıyoruz.

sonuç1.png

Sonuç ekrana bu şekilde basılıyor.

Github : https://github.com/php/php-src



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

eline sağlık

teşekkür ederim

Hey @sinankarayaman I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x