the easiest way would be: <? // -------------
// init var $str = ""; $str = "abc def ghi"; $str = str_replace (" ", "", $str); echo $str."<br>"; // ---------------------------- // output: // abcdefghi // ---------------------------- // // or a regex: $str = "abc def ghi"; $str = ereg_replace(" ", "", $str); echo $str."<br>"; //if you want to strip any whitespace character: $str = "abc def ghi"; $str = preg_replace("/\s/", "", $str); echo $str."<br>"; // ------------- ?> preg_replace is quite powerful, so if you only want to strip some spaces, you should prefer str_replace. Always think about how many power you need. str_replace -> ereg_replace -> preg_replace. Michael "Chris Boget" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 007f01c1d502$b70b3360$[EMAIL PROTECTED]">news:007f01c1d502$b70b3360$[EMAIL PROTECTED]... > > Say I have a string "xyz abc def" and I want to remove all of the spaces > > withing the string to create a new one. What's the best way? > > <? > > $string = "xyz abc def"; > > $stringWithOutSpaces = implode( "", explode( " ", $string )); > > ?> > > Or you can use eregi_replace(), but I don't know what the regex would be. > I *think* you can do: > > <? > > $string = "xyz abc def"; > > $stringWithOutSpaces = eregi_replace( " ", "", $string ); > > ?> > > > Chris > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php