Closed mgarimelHES closed 2 years ago
The solution I found that worked well for me was using Regular Expressions to find the non-alphabetic characters and remove them.
There are several ways to go about this.
As @dauger27 suggested, you could work with a regular expression combined with one of php's built in reg exp. functions, e.g. preg_filter.
Or, as you noted, you could use ctype_alpha, but you would want to combine this some way of filtering just the letters. This could be as simple as a loop that goes through each character in the string and disregards any characters that don't pass ctype_alpha.
Or, a similar loop/filter approach could be accomplished with array_filter.
Thanks @dauger27 and @susanBuck , I will try the suggested options.
Appreciate your help
Thanks, able to do it with ctype_char.
I am wondering if there is any way we could check for non-alphabet characters as shown in the notes for Palindrome (ex- "!racecar!")?
One way that I am thinking about leveraging the built-in function like 'ctype_alpha', not sure if there are better options exist?
Thanks