clarencek Posted July 1, 2006 Share Posted July 1, 2006 Hi, I'm a bit new at php and need help with some string manipulation.I'm getting a variable out of my database with this call: $t_city = $row['t_city']; Basically $t_city = "New York". What I want to do is manipulate the string such that it becomes "New+York".I was trying this, but it doesn't seem to work:$t_city = str_replace(\' \',\'+\',$t_city);What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/13367-help-to-change-string-from-space-to/ Share on other sites More sharing options...
Orio Posted July 1, 2006 Share Posted July 1, 2006 $t_city = str_replace(' ','+',$t_city);No need to escape :)Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13367-help-to-change-string-from-space-to/#findComment-51594 Share on other sites More sharing options...
mrwhale Posted July 1, 2006 Share Posted July 1, 2006 [code]<?php$text = "hello this is a string";$text = str_replace( " ", "+", $text );echo $text;?>[/code]This is how :) Quote Link to comment https://forums.phpfreaks.com/topic/13367-help-to-change-string-from-space-to/#findComment-51595 Share on other sites More sharing options...
clarencek Posted July 1, 2006 Author Share Posted July 1, 2006 Thanks for the rapid response. Isn't the Internet wonderful? Quote Link to comment https://forums.phpfreaks.com/topic/13367-help-to-change-string-from-space-to/#findComment-51598 Share on other sites More sharing options...
.josh Posted July 1, 2006 Share Posted July 1, 2006 no. it's evil. it is because of the internet that i am still up right now. :P Quote Link to comment https://forums.phpfreaks.com/topic/13367-help-to-change-string-from-space-to/#findComment-51604 Share on other sites More sharing options...
clarencek Posted July 1, 2006 Author Share Posted July 1, 2006 hahaha...i hear ya. there's no reason i should be staying up till 4 AM two nights in a row. i don't think i'll pull a 3rd night. time for me to go to bed! Quote Link to comment https://forums.phpfreaks.com/topic/13367-help-to-change-string-from-space-to/#findComment-51608 Share on other sites More sharing options...
shoz Posted July 1, 2006 Share Posted July 1, 2006 If this is about adding the value to a url, you may want to look at [url=http://www.php.net/urlencode]urlencode[/url] Quote Link to comment https://forums.phpfreaks.com/topic/13367-help-to-change-string-from-space-to/#findComment-51617 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.