String Functions in PHP: PART 4

Introduction

In this article I describe the PHP string functions count_chars, crc32 and explode. To learn some other math functions, go to:

  1. String Functions in PHP: Part1
     
  2. String Functions in PHP:Part2
     
  3. String Functions in PHP:Part3

PHP count_chars() Function

The PHP string count_chars function returns information about the characters used in a string.

Syntax

count_chars (string, node)

Parameter in count_chars Function

The parameters of the count_chars function are:

Parameter Description
string It specifies the string to be checked.
mode It specifies the returns mode. The returns mode are:

0: An array with the byte-value as key and the frequency of every byte as value.

1: Same as 0 but only byte-value with a frequency greater than zero are listed.

3: Same as 0 but byte value with a frequency equal to zero are listed.

4: A string containing all unique characters is returned.

5: A string containing all unused characters is returned.

Example

An example of the
count_chars function is:

<?
php
$
str="MCN Solution";
echo
"<pre>";
print_r
( count_chars($str,1));
?>


Output

count-chars -string-function-in-php.jpg


PHP crc32() Function

The PHP string crc32 function calculates the crc32 polynomial of a string. This function can be used to validate data integrity.


Syntax

crc32(string)

Parameter in crc32 Function

The parameter of the crc32 function is:

Parameter Description
string It specifies the string to be calculate.

Example

An example of the
crc32 function is:

<?php

$str = crc32("MCN Solution.");

printf("%u\n", $str);

?>

Output

crc32-string-function-in-php.jpg 

PHP explode() Function

The PHP string explode function splits a string into an array.


Syntax

explode (separator, string,limit)

Parameter in explode Function

The parameters of the explode function are:

Parameter Description
separator It specifies where to break the string.
string It specifies the string to split.
limit It specifies the maximum number of array element to return.

Example

An example of the
explode function is:

<?php

$str = "MCN Solution PVT LTD.";

echo "<pre>";

print_r(explode(" ",$str));

?>

Output

explode-string-function-in-php.jpg


Similar Articles