Php > Arrays
Counting Words in Alpanumeric Strings
Counting Words in Alpanumeric Strings str_word_count works great on alaphabetic strings (if you clean the text first) but doesn't include numbers (numeric strings). I couldn't use it on a recent project because I needed to count numeric strings (phone numbers, etc) as words. Default str_word_count // remove excess spaces between words $string = ereg_replace(" +"," ","$string"); // remove leading and trailing spaces $string = trim($string); // count number of words $numwords = str_word_count($string); ?> The above wass inaccurate for my purpose so to count the number of elements in an alphanumeric string clean the data then create and count an array. $string = ereg_replace(" +", " ", $string); $string = trim($string); // count number of words $numwords = explode(" ", $string); $numwords = count ($numwords); ?> Thanks for all the help, hope I'm giving something back.
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage