?
Solved

Removing white spaces in a string

Posted on 2003-03-12
4
Medium Priority
?
152 Views
Last Modified: 2008-02-20
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
Comment
Question by:server_room
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
wide_awake earned 200 total points
ID: 8121387
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
 
LVL 1

Author Comment

by:server_room
ID: 8121448
You almost had it but I modified it to this and it worked!

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

Thanks!
0
 
LVL 1

Author Comment

by:server_room
ID: 8121477
Your solution worked! Thanks again!
0
 
LVL 3

Expert Comment

by:wide_awake
ID: 8122481
Glad it helped.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question