PHP Strings

Posts about manipulating strings in different ways in PHP

Extend The str_word_count Function In PHP

22nd January 2008 - 5 minutes read time

The str_word_count() function in PHP does exactly what is says it does. The default of this function is to simply count the number of words present. Take the following string.

$str = "This is a 'string' containing m0re than one word. This is a 'string' containing m0re than one word.";

If we pass this to the str_word_count() function with no other parameters we get the number of words.

Does A String In PHP Contain A Number?

24th December 2007 - 2 minutes read time

The is_numeric() function in PHP can be used to see if a number contained in a string is numeric. The function returns true is the variable can be parsed into a string, otherwise it returns false. Here are some examples: