dadamssg Posted April 10, 2009 Share Posted April 10, 2009 i want to create a form field where the input will get put into a google maps link...so i need to replace the spaces with +'s...for example if i input 3278 Blue Jay dr, scottsdale AZ 44559 it will eventually look like http://maps.google.com/maps?saddr=3278+blue+jay+dr,+scottsdale+AZ+44559&hl=en Link to comment https://forums.phpfreaks.com/topic/153487-solved-replace-blanks-with-s/ Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 $string = str_replace(' ', '+', $string); or $string = preg_replace('/\s/', '+', $string); Link to comment https://forums.phpfreaks.com/topic/153487-solved-replace-blanks-with-s/#findComment-806440 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 What you need is urlencode(). echo urlencode("3278 Blue Jay dr, scottsdale AZ 44559"); Link to comment https://forums.phpfreaks.com/topic/153487-solved-replace-blanks-with-s/#findComment-806441 Share on other sites More sharing options...
ToonMariner Posted April 10, 2009 Share Posted April 10, 2009 $str = '3278 Blue Jay dr, scottsdale AZ 44559'; $str = preg_replace('/\s+/','+',$str); Link to comment https://forums.phpfreaks.com/topic/153487-solved-replace-blanks-with-s/#findComment-806443 Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 Yeah, i forgot about urlencode() Better option. Link to comment https://forums.phpfreaks.com/topic/153487-solved-replace-blanks-with-s/#findComment-806445 Share on other sites More sharing options...
dadamssg Posted April 10, 2009 Author Share Posted April 10, 2009 awesome, thanks! Link to comment https://forums.phpfreaks.com/topic/153487-solved-replace-blanks-with-s/#findComment-806447 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 No need for a regex solution when there is a native function already designed for this. Link to comment https://forums.phpfreaks.com/topic/153487-solved-replace-blanks-with-s/#findComment-806449 Share on other sites More sharing options...
ToonMariner Posted April 10, 2009 Share Posted April 10, 2009 touche... lol - i was actually looking for the server settings - thought you could choose which character replaces ' ' - too many times i see it use %20 funnily enough thats the way to go as in this case each and every response is pointless!!! you need to submit the form with the get method for any search functionality worth its salt (want to be able to save searches) therefore you won't even get the chance to convert the search string until its received on the next page... Link to comment https://forums.phpfreaks.com/topic/153487-solved-replace-blanks-with-s/#findComment-806574 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 touche... Hehehe, I only said cause you said it in the other thread... Link to comment https://forums.phpfreaks.com/topic/153487-solved-replace-blanks-with-s/#findComment-806593 Share on other sites More sharing options...
ToonMariner Posted April 10, 2009 Share Posted April 10, 2009 i know mate!!! - pot to kettle and all that Link to comment https://forums.phpfreaks.com/topic/153487-solved-replace-blanks-with-s/#findComment-806597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.