remove spaces - no line brakes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

remove spaces - no line brakes

Post by pedroz »

I have this funtion below to:
1. remove multiple spaces from textarea
2. space at the end of the string...

Code: Select all

function space($string) {	
$string = eregi_replace('^[[]]+', '',preg_replace('/\s+/', ' ', $string));	
return $string; 
}
How can avoid removing the line breaks?

example:
Hi...
How are you?

with the function above it will result
Hi... How are you?

... removing me the line break and I only want to remove extra spaces
User avatar
kreoton
Forum Commoner
Posts: 42
Joined: Fri Mar 03, 2006 7:27 pm

Post by kreoton »

i think function nl2br()may help you ;)
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

Post by pedroz »

I found it... Thanks!

Code: Select all

$string = eregi_replace('^[[]]+', '', ereg_replace (' +', ' ', $string));
Post Reply