PHP count_chars() ਫੰਕਸ਼ਨ
ਉਦਾਹਰਣ
ਵਾਪਸੀ ਇੱਕ ਸਟਰਿੰਗ ਪ੍ਰਦਾਨ ਕਰਦੀ ਹੈ ਜਿਸ ਵਿੱਚ 'Hello World!' ਵਿੱਚ ਵਰਤੇ ਗਏ ਵੱਖ-ਵੱਖ ਅੱਖਰ ਹਨ (ਮੋਡ 3):
<?php $str = "Hello World!"; echo count_chars($str,3); ?>
ਪਰਿਭਾਸ਼ਾ ਅਤੇ ਵਰਤੋਂ
count_chars() ਫੰਕਸ਼ਨ ਸਟਰਿੰਗ ਵਿੱਚ ਵਰਤੇ ਗਏ ਅੱਖਰਾਂ ਦੀ ਸੂਚਨਾ ਦਾ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ (ਉਦਾਹਰਣ ਵਜੋਂ, ਸਟਰਿੰਗ ਵਿੱਚ ਕਿਸੇ ਅੱਖਰ ਦੀ ਸੰਖਿਆ ਜਾਂ ਕਿਸੇ ਅੱਖਰ ਦਾ ਉਪਯੋਗ ਕੀਤਾ ਗਿਆ ਹੈ ਜਾਂ ਨਹੀਂ)。
ਸਿਫ਼ਟਾਕਸ
count_chars(string,mode)
ਪੈਰਾਮੀਟਰ | ਵਰਣਨ |
---|---|
string | ਲਾਜ਼ਮੀ ਹੈ। ਜੋ ਚੈਕ ਕਰਨੇ ਹਨ ਦੇ ਲਈ ਨਿਰਧਾਰਿਤ ਹੈ। |
mode |
ਚੋਣੀ ਹੋ ਸਕਦੀ ਹੈ। ਵਾਪਸੀ ਮੋਡ ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰੋ। ਮੂਲ ਮੋਡ 0 ਹੈ। ਹੇਠ ਵਿੱਚ ਵੱਖ-ਵੱਖ ਵਾਪਸੀ ਮੋਡ ਹਨ:
|
Technical Details
Return Value: | depending on the specified mode Parameters. |
PHP Version: | 4+ |
More Examples
Example 1
Returns a string containing all unused characters in "Hello World!" (pattern 4):
<?php $str = "Hello World!"; echo count_chars($str,4); ?>
Example 2
In this example, we will use count_chars() to check the string, with the return pattern set to 1. Pattern 1 will return an array with ASCII values as key names and the number of occurrences as key values:
<?php $str = "Hello World!"; print_r(count_chars($str,1)); ?>
Example 3
Another example of counting the number of occurrences 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>"; } ?>