Is there a way to check if the first character of a string is a letter or a number? I'm not really sure what function to use. Is there a way to check not using regex, as we have not learned that yet in my class.
I'd encourage you to read more about strings in PHP. For example, you can dereference them like arrays to get individual characters.
$letters = 'abcd';
echo $letters[0];
There are also a handful of ctype
functions. Check out, ctype_digit()
and [ctype_alpha()
}(http://php.net/manual/en/function.ctype-alpha.php).
ctype_digit($letters[0]); // false
ctype_alpha($letters[0]); // true
Putting these together, you should be able to do what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With