954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

remove white spaces in array values

Hi

I have the following array:

$links = array("Home", "About us", "Our Services");


foreach($links as &$link ){
	
$space =	implode(" ", $links);
	
	echo $space ;
	break;
	
	
	
}

the above code displays Home About us Our Services, but now I want to use the same array for links so each one of the sections needs to be linked, how can I remove the white spaces so "

About us


" becomes "

aboutus


".

Thanls

andy106
Newbie Poster
20 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 
$myurl="About us";
$mynewurl=strtolower(str_replace(" ","",$myurl));
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
 

Pretty much as urtrivedi says.

$links = array("Home", "About us", "Our Services");
foreach($links as &$link ){
	$link = strtolower(str_replace(" ","",$link));
}


Although you've now changed the original array.

$links = array("Home", "About us", "Our Services");
foreach($links as $link ){
	$urls[] = strtolower(str_replace(" ","",$link));
}


will place new array as $urls

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: