str_replace not working

trying to truncate the spaces and
's on this ****ing string and they wont go away

	for($j=0;$j<$count;$j++)
	{
		$fieces = explode(" ", $pieces[$j], 2);
		echo $fieces[1];
		$string = str_replace("\
", "", $fieces[1]);
		echo $string;
		$string2 = str_replace(" ", "", $string);
		echo $string2;
		$dbmember[$j]=$string2;
		echo "debug ".$pieces[$j].", ".$dbmember[$j]."<br/>";
		for($k=0;$k<$i;$k++)
		{
			if($dbmember[$j]==$name[$k])
			{
				echo "match at ".$k.": ".$dbmember[$j].", ".$name[$k]."<br/>";
				if($check[$j]==0)
				{
					$check[$j]=1;
				}
				else
				{
					die("you have entered the same rank twice");
				}
			}
			else
			{
				echo "no match :".$dbmember[$j].", ".$name[$k]."<br/>";
			}

		}
	}

no matter what i do theres still a
at the end

nm it was just M$ ading their own handy \r newline to everything
god bless M$ and all their time saving features

Why not just use trim?


$string = trim($fieces[1]);

It will remove all whitespace characters from the beginning and end of the string in one go.

excelent, i will make extensive use of trim in future projects
thaky u diggy

use trim to truncate all space before and after a text like ’ my text ’ ==> ‘my text’
Use preg_replace

$text = '      my    text      ';
$text = preg_replace("/([\\s]+)/"," ",trim($text));

out put –> ‘my text’