دالة PHP str_word_count ()
مثال
احسب عدد الكلمات الموجودة في السلسلة "Hello World!":
<?php
echo str_word_count("Hello world!");
?>
التعريف والاستخدام
تحسب الدالة str_word_count () عدد الكلمات في سلسلة.
بناء الجملة
str_word_count(string,return,char)
قيمه المعامل
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. |
تفاصيل تقنية
قيمة الإرجاع: | إرجاع رقم أو مصفوفة ، بناءً على معامل الإرجاع المختار |
---|---|
إصدار PHP: | 4.3.0+ |
التغيير: | تمت إضافة معامل char في PHP 5.1 |
مزيد من الأمثلة
مثال
إعادة مصفوفة بالكلمات من السلسلة:
<?php
print_r(str_word_count("Hello world!",1));
?>
مثال
قم بإرجاع مصفوفة حيث يكون المفتاح هو موضع الكلمة في السلسلة ، والقيمة هي الكلمة الفعلية:
<?php
print_r(str_word_count("Hello world!",2));
?>
مثال
بدون ومع المعلمة char:
<?php
print_r(str_word_count("Hello world & good morning!",1));
print_r(str_word_count("Hello world & good morning!",1,"&"));
?>
❮ مرجع سلسلة PHP