Anyone knows how to compute the the alphabets of string in php Without any inbuilt function?? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Anyone knows how to compute the the alphabets of string in php Without any inbuilt function??

25th Sep 2018, 8:41 AM
kunal
kunal - avatar
3 Respostas
+ 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?
25th Sep 2018, 10:11 AM
Ipang
+ 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
25th Sep 2018, 11:18 AM
Ipang
0
Yes count total number of letters in a string without using strlen() function.
25th Sep 2018, 10:30 AM
kunal
kunal - avatar