Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • Last Modified:

Removing white spaces in a string

I have hundreds of strings in an array that need to be seperated as in city and state

example:

*************************

Eatontown   NJ

Hazlet      NJ

Highland Park       NJ

etc...


btw, all these strings have a variant amount of spaces :(
So I can't just do explode()
*************************

Is there a way to get these seperated?
0
server_room
Asked:
server_room
  • 2
  • 2
1 Solution
 
wide_awakeCommented:
hi.

Use the "split" function - it allows you to split on an expression, rather than a specific char.

http://www.php.net/manual/en/function.split.php

So you could use:

list($city, $state) = split(' +', $stringToSplit);


-Mark.
0
 
server_roomAuthor Commented:
You almost had it but I modified it to this and it worked!

list($city, $state) = split(' + +', $stringToSplit);

Thanks!
0
 
server_roomAuthor Commented:
Your solution worked! Thanks again!
0
 
wide_awakeCommented:
Glad it helped.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now