jonaofarc Posted August 17, 2008 Share Posted August 17, 2008 how does one add a + between words in a string? so if we have a text box and someone types john doe I would like it to come back john+doe with no spaces Link to comment https://forums.phpfreaks.com/topic/120048-how-does-one-add-a-between-words-in-a-string/ Share on other sites More sharing options...
marcus Posted August 17, 2008 Share Posted August 17, 2008 <?php $string = "john doe"; echo str_replace(" ","+",$string); ?> Link to comment https://forums.phpfreaks.com/topic/120048-how-does-one-add-a-between-words-in-a-string/#findComment-618398 Share on other sites More sharing options...
thebadbad Posted August 17, 2008 Share Posted August 17, 2008 If it's because you want to use the string as a query string part of an URL, you can urlencode() the string. That'll convert spaces to + and, and convert other 'illegal' characters. Link to comment https://forums.phpfreaks.com/topic/120048-how-does-one-add-a-between-words-in-a-string/#findComment-618433 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.