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 Link to comment https://forums.phpfreaks.com/topic/72933-convert-variable-to-lowercase-and-with-s-instead-of-spaces/ 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)); Link to comment https://forums.phpfreaks.com/topic/72933-convert-variable-to-lowercase-and-with-s-instead-of-spaces/#findComment-367804 Share on other sites More sharing options...
Sam Granger Posted October 12, 2007 Author Share Posted October 12, 2007 Thanks a bunch! Link to comment https://forums.phpfreaks.com/topic/72933-convert-variable-to-lowercase-and-with-s-instead-of-spaces/#findComment-367826 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 Link to comment https://forums.phpfreaks.com/topic/72933-convert-variable-to-lowercase-and-with-s-instead-of-spaces/#findComment-368173 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 _ Link to comment https://forums.phpfreaks.com/topic/72933-convert-variable-to-lowercase-and-with-s-instead-of-spaces/#findComment-368358 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... Link to comment https://forums.phpfreaks.com/topic/72933-convert-variable-to-lowercase-and-with-s-instead-of-spaces/#findComment-369836 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.