Re: Removing Spaces from Array Values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



kvigor wrote:
Need to remove all spaces from Array Values... And this doesn't work.
Are we talking spaces ' ' or all white space?  This may include a tab, space, new line, etc...


This is similar info that's within array values: $someArray[0] = "PHP is awesome"; s/b PHPisawesome This is similar info that's within array values: $someArray[1] = "The Toy Boat"; s/b TheToyBoat

Begin Code===================================
$num = count($someArray);

for($num = 0; $cntr < $num; $cntr++)
{
 str_replace(' ','',$someArray[$num]);
 echo "$someArray[$num]<br />";
}
End Code===================================

This should do for you

<plaintext><?php

$someArray = array();

$someArray[] = "somethig specia	to take apart";
$someArray[] = "somethig
specia	to take apart";
$someArray[] = "somethig specia	to
take apart
";

print_r($someArray);

foreach ( $someArray AS $k => $v ) {

	$someArray[$k] = preg_replace('!\s!', '', $v);	// Removes white space ' ', \n, \r\n, etc...

	$someArray[$k] = str_replace(' ', '', $v);	// Removes only spaces

}

print_r($someArray);


--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux