Anyone know of a function that will count only the number of letters in a string and only the number of digits in a string?
php question ...
Collapse
X
-
Tags: None
-
PHP Code:<?php $str = "00jkjdj0"; $char_count = 0; $num_count = 0; $u_bound = strlen( $str ) - 1; for( $i = 0 ; $i <= $u_bound ; $i++ ) { if( is_numeric( $str{ $i } ) ) { $char_count++; } else { $num_count++; } } echo $char_count; echo $num_count; ?>Comment
-
Sorry. I mixed up my variabless in the following line (unless you want to use $char_count as the number count variable and $num_count as the character count variable
) ...
It should read...PHP Code:if( is_numeric( $str{ $i } ) ) { $char_count++; } else { $num_count++; }
PHP Code:if( is_numeric( $str{ $i } ) ) { $num_count++; } else { $char_count++; }
Full code:
PHP Code:$str = "00jkjdj0"; $char_count = 0; $num_count = 0; $u_bound = strlen( $str ) - 1; for( $i = 0 ; $i <= $u_bound ; $i++ ) { if( is_numeric( $str{ $i } ) ) { $num_count++; } else { $char_count++; } } echo $char_count; echo $num_count;Comment
-
Its cheaper to outsource the job to eager young pakistani counting expertshatisblack at yahoo.comComment

Comment