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!

Removing large whitespaces in middle of text

Status
Not open for further replies.

Zych

IS-IT--Management
Apr 3, 2003
313
US
How can one remove large amounts of whitespace in a text string? I do not want to remove the spaces between standard words. For example lets say I have this string:

This is the most helpful forum. You should join it!


I would want to change it to:

This is the most helpful forum. You should join it!

I don't really care if there is two spaces after a period but it would be nice. I have seen replacement strings that replace the whitespace so it is all gone but as I said I want to keep the standard spacing.

Thanks,

Zych
 
Well, i asume you always have more than 2 whitespaces between your two text parts.

So you should try something like

Code:
$newtext=ereg_replace("  ", "", $oldtext)

this should erase all "double-whitespaces" by replacing them with an empty string.

I'm not sure if it works 'cause I don't have a php-System nearby but if PHP doesn't behave different to other languages, this should do it
 
Thanks, I actually made a while loop to change three spaces to two. However I think my problem is line feeds and/or carriage returns. I am trying to figure out how to do this.

- Zych
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top