renno Posted November 24, 2006 Share Posted November 24, 2006 I have a variable containing a string submitted from a form:[code]$string = ($_POST["string"]);[/code]I'm struggling to build some code that would replace any spaces in the string with the underscore character and then store back into a different variable $string2...Could anyone give me a point in the right direction?Cheers Link to comment https://forums.phpfreaks.com/topic/28328-replace-space-with-underscore-character-in-string/ Share on other sites More sharing options...
kenrbnsn Posted November 24, 2006 Share Posted November 24, 2006 The function you're looking for is [url=http://www.php.net/str_replace]str_replace()[/url][code]<?php$str2 = str_replace(' ','_',$_POST['string']);?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/28328-replace-space-with-underscore-character-in-string/#findComment-129572 Share on other sites More sharing options...
CheesierAngel Posted November 24, 2006 Share Posted November 24, 2006 You should take a look at str_raplace() function.- [url=http://php.belnet.be/manual/en/function.str-replace.php]http://php.belnet.be/manual/en/function.str-replace.php[/url]str_replace -- Replace all occurrences of the search string with the replacement string Link to comment https://forums.phpfreaks.com/topic/28328-replace-space-with-underscore-character-in-string/#findComment-129573 Share on other sites More sharing options...
renno Posted November 24, 2006 Author Share Posted November 24, 2006 Thankyou all, much appreciated... Link to comment https://forums.phpfreaks.com/topic/28328-replace-space-with-underscore-character-in-string/#findComment-129587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.