This I thought would be simple but I can't seem to find a way of removing a space from between two numbers, it is actually a phone number with any prefix needed before the number which will be seperated by a space, take $phone = "456 56789"; I just need to know if the variable contains digits and or digits and spaces.
I thought that I could replace the " " with "" using the strtr function then use is_numeric but the strtr function does not seem to work with spaces, I thought there might be a function like trim that would remove all the spaces but there does not seem to be one in the manual, isn't there any simple way of doing this?
Removing a space from between digits
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Use str_replace():
Mac
Code: Select all
/* Remove all spaces from a string */
$string_without_spaces = str_replace(' ', '', $string_with_spaces);