PHP count_chars() ফাংশন
উদাহরণ
একটি স্ট্রিং প্রত্যাহার করে, যাতে "Hello World!"-এর মধ্যে ব্যবহৃত সকল আলাদা অক্ষরগুলো থাকে (মোড 3):
<?php $str = "Hello World!"; echo count_chars($str,3); ?>
সংজ্ঞা ও ব্যবহার
count_chars() ফাংশন স্ট্রিংয়ের ব্যবহৃত অক্ষরগুলোর তথ্য প্রদান করে (যেমন, ASCII অক্ষরগুলোর স্ট্রিংয়ের মধ্যে উপস্থিতির সংখ্যা, বা কোনও অক্ষর স্ট্রিংয়ের মধ্যে কতবার ব্যবহৃত হয়েছে)。
গঠনশৈলী
count_chars(string,mode)
পারামিটার | বর্ণনা |
---|---|
string | অপরিহার্য।নির্দিষ্ট করা হওয়া চিহ্নিত স্ট্রিং |
mode |
অপশনাল।প্রত্যাহার মোড়কে নির্দিষ্ট করুন।ডিফল্ট 0।নিচে বিভিন্ন প্রত্যাহার মোড়গুলো দেখুন:
|
Technical Details
Return Value: | depending on the specified mode Parameters. |
PHP Version: | 4+ |
More Examples
Example 1
Return a string containing all unused characters in "Hello World!" (mode 4):
<?php $str = "Hello World!"; echo count_chars($str,4); ?>
Example 2
In this example, we will use count_chars() to check the string, the return mode is set to 1. Mode 1 will return an array, the ASCII value is the key name, and the occurrence is the key value:
<?php $str = "Hello World!"; print_r(count_chars($str,1)); ?>
Example 3
Another example of counting the occurrence of an ASCII character in a string:
<?php $str = "PHP is pretty fun!!"; $strArray = count_chars($str,1); foreach ($strArray as $key=>$value) { echo "Character <b>'".chr($key)."'</b> found $value times.<br>"; } ?>