Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting spaces of a string

Status
Not open for further replies.

axmug

Programmer
Oct 13, 2003
34
ES
I'm trying deleting spaces of a string and once deleted I want to obtain a new string with _ instead of spaces. For example: I have a string with the value Matrix Revolutions and I want to obtain an string like Matrix_Revolutions. I can obtain an array with both values: Matrix and Revolutions. The problem is to get the string Matrix_Revolutions. I don't know how to do it. I have tried the following:

$dname=explode(" ",$cat); //it works ok
$cat=$dname[0]+"_"+$dname[1]; //it doesn't work. $cat value is 0.

How can I do it?
Thanks.
 
axmug,

Just use the reverse function to explode, called ...you've guessed it now: explode(). Like this:

Code:
$dname=explode(" ",$cat);
$d_name = implode("_", $dname);

Good luck §;O)


Jakob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top