woocha Posted December 16, 2007 Share Posted December 16, 2007 Hey Guys.. I have a quick questions here about user input forms. I have a form that a user fills out and I want them to be able to insert a phrease of 2-5 words not just one word (example: I Love PHPFreaks). The field is turned into a viariable called $notes the variable is then turned into a file name such as $notes.txt. I want it so that the 2-5 word phrase can be turned into I_Love_PHPFreaks This way when the file(I_Love_PHPFreaks.txt) is on the server, it can still work. Is there a function for this? Thank you Quote Link to comment Share on other sites More sharing options...
paul2463 Posted December 16, 2007 Share Posted December 16, 2007 $string = "I Love PHPFreaks"; $newString = str_replace(" ", "_", $string); //replaces all spaces with the underscore echo $newString; // writes I_Love_PHPFreaks Quote Link to comment Share on other sites More sharing options...
papaface Posted December 16, 2007 Share Posted December 16, 2007 What happens if they use: "I_Love_PHPFreaks." ... Remember to strip out anything except spaces and letters/numbers. Quote Link to comment Share on other sites More sharing options...
woocha Posted December 16, 2007 Author Share Posted December 16, 2007 $string = "I Love PHPFreaks"; $newString = str_replace(" ", "_", $string); //replaces all spaces with the underscore echo $newString; // writes I_Love_PHPFreaks Thanks a lot man... I really appreciate it. Quote Link to comment Share on other sites More sharing options...
woocha Posted December 16, 2007 Author Share Posted December 16, 2007 What happens if they use: "I_Love_PHPFreaks." ... Remember to strip out anything except spaces and letters/numbers. do you mean with strip_tags? how would I use that or should I use someting else? Quote Link to comment Share on other sites More sharing options...
woocha Posted December 16, 2007 Author Share Posted December 16, 2007 $string = "I Love PHPFreaks"; $newString = str_replace(" ", "_", $string); //replaces all spaces with the underscore echo $newString; // writes I_Love_PHPFreaks Would this work as well? $newString = str_replace(" ", "aeiou", $string); //replaces all spaces with the underscore meaning, Can I replace the space with more than one character if I had or wanted to? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted December 16, 2007 Share Posted December 16, 2007 yes Quote Link to comment Share on other sites More sharing options...
woocha Posted December 16, 2007 Author Share Posted December 16, 2007 yes Thanks dude Quote Link to comment 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.