Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex leaving 1 space in a string

Status
Not open for further replies.

peterworth

Programmer
Aug 18, 2004
80
GB
i'm trying to do the following and have got a bit confused:

replace a string so that only alpha-numeric characters remain, deleting spaces and all EXCEPT if there is a space in the middle of the string - then keep it. if there are spaces at the end or beginning of the string (before or after all alpha-numeric characters) delete them, and if there is more than one space in the middle of the string then only keep the one nearest the end...

i just want to use a few preg_replace calls in PHP to do this.

thanks for any help.
 
How about skipping the regex for the spaces at the beginning and at the end and going with trim()?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top