0
Anyone knows how to compute the the alphabets of string in php Without any inbuilt function??
3 Antworten
+ 2
What do you mean compute alphabets? count total letters in range A-Z, a-z? or digits included? I can only think of using a loop though, what you have in mind? got any code in progress?
+ 1
I will assume you meant alphabetical letters as per your confirmation. I will give you some hints to get you started with:
* Create a counter variable initialized to zero -> $counter
* Create a loop iterator also with zero -> $n
* Run a while loop with condition to check, whether a character at $n-th position is valid char using isset() function.
* Inside loop body you use ctype_alpha() function to check if character at $n-th position is an alphabet, increment $counter variable if it is. Don't forget to also increment the loop iterator $n.
At the end of the loop, you will have a total alphabetical characters in the string, stored in $counter.
NOTE: This suggestion is only valid for string containing standard ASCII character set, Unicode or UTF characters needs a different approach.
Hth, cmiiw
References:
[ctype_alpha function]
http://php.net/manual/en/function.ctype-alpha.php
0
Yes count total number of letters in a string without using strlen() function.