Sam Granger Posted October 12, 2007 Share Posted October 12, 2007 Hey guys! Lets say I have a variable. Sometimes it contains 1 or more spaces. How can I replace the spaces with '-'? Sam Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 12, 2007 Share Posted October 12, 2007 $string = "This Is A sTrING"; $string = str_replace(' ',',',strtolower($string)); Quote Link to comment Share on other sites More sharing options...
Sam Granger Posted October 12, 2007 Author Share Posted October 12, 2007 Thanks a bunch! Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 12, 2007 Share Posted October 12, 2007 pitty i put , instead of the - you asked for Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 13, 2007 Share Posted October 13, 2007 Don't replace spaces with - or php will think you're trying to subtract things. Replace the spaces with the underscore character _ Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 15, 2007 Share Posted October 15, 2007 surely only when using eval??? I don't use underscores in file names - accessibility and all that - if people look at a link to a file and there is an underscore in it while the link has underlined text decoration then they may be confused - just my way if you are consistent then you find you have less problems (as always). Never had a problem with php thinking I am trying to subtract strings... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.