[RESOLVED] PHP Function to check if a character in a string is a number vs a letter
I have a string of a random length and I need all of the NUMBERS in the string to display as red... like if the string is aoga7sha3a0a or something, then the 7, 3, and 0 should be red. I'm thinking a simple...
...should work just fine, but my problem is getting them there... I need a PHP function that can check each character in the string and if it's a number (which would only be 0 1 2 3 4 5 6 7 8 or 9) then it adds the "stuff" around it to make it red...
The reason I'm doing this is so that when the administrator looks at the list of usernames and passwords she doesn't tell them (on the phone if they're having trouble logging in) to put in 101 if it's loi or something...
Any suggestions would be greatly appreciated. Thanks!
preg_replace('/[0-9]/', '<span class="rednum">$0</span>', $string)
You could clean up the HTML a bit with the following small change, so that consecutive number characters would be in one span:
Originally Posted by NogDog
preg_replace('/[0-9]+/', '<span class="rednum">$0</span>', $string)
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)