PHP str_word_count() Fonksiyon
Örnek
"Merhaba Dünya!" dizesinde bulunan kelime sayısını sayın:
<?php
echo str_word_count("Hello world!");
?>
Tanım ve Kullanım
str_word_count() işlevi, bir dizedeki sözcük sayısını sayar.
Sözdizimi
str_word_count(string,return,char)
Parametre Değerleri
Parameter | Description |
---|---|
string | Required. Specifies the string to check |
return | Optional. Specifies the return value of the str_word_count() function. Possible values:
|
char | Optional. Specifies special characters to be considered as words. |
Teknik detaylar
Geri dönüş değeri: | Seçilen dönüş parametresine bağlı olarak bir sayı veya dizi döndürür |
---|---|
PHP Sürümü: | 4.3.0+ |
Değişiklik günlüğü: | PHP 5.1'de char parametresi eklendi |
Daha fazla örnek
Örnek
Dizedeki sözcükleri içeren bir dizi döndürün:
<?php
print_r(str_word_count("Hello world!",1));
?>
Örnek
Anahtarın dizedeki sözcüğün konumu olduğu ve değerin gerçek sözcük olduğu bir dizi döndürün:
<?php
print_r(str_word_count("Hello world!",2));
?>
Örnek
char parametresi olmadan ve ile:
<?php
print_r(str_word_count("Hello world & good morning!",1));
print_r(str_word_count("Hello world & good morning!",1,"&"));
?>
❮ PHP Dize Referansı