PHP uses number of integrated functions for working with characters in a string. The list of characters manipulating functions is shown below.

The characters manipulating functions in PHP:

The trim() function

The trim() function is used to strip white spaces at the beginning and the end of the string.

Syntax for trim()

string trim ( string $str [, string $character_mask = " \t\n\r\0\x0B" ] );

NOTE: If none of further commands or statement is being used, a trim() function will return a string with whitespace stripped from the beginning to the end. 

Multiple examples of trim() function usage

The substr_count() function

The substr_count() function is used to count the number of substring occurrences.

Syntax for substr_count()

int substr_count ( string $haystack , string $needle [, int $offset = 0 [, int $length ]] );

This function returns the number of times the needle substring occurs in the haystack string, or in other words the needle is a substring to search for and the haystack is the string to search in. The needle is also case sensitive. 

Example with substr_count() functions


›› go to examples ››