View Full Version : remove more then 1 spaces from string

01-22-2012, 12:36 PM

I have a variable which returning a string with more then 1 spaces like this (<p> This is a test string from a variable </p>)

I need to use a php function which can remove all extra spaces like this (<p> This is a test string from a variable</p>)


01-22-2012, 01:08 PM
Can you be more specific about where the spaces could possibly be? Are they always at the end of a string followed by a closing </p> tag?

01-22-2012, 01:13 PM
no, the string is not with specific data

01-22-2012, 01:37 PM
Without having a general idea of what your strings will look like, it's hard to find a regular expression or algorithm to handle the issue.

PHP has a function called trim() that removes spaces from the beginning and end of lines...maybe that helps. Do you have some real data you can post along with what they should look like after removing the spaces?