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 Link to comment https://forums.phpfreaks.com/topic/81935-using-a-php-function-to-make-a-viable-file-name-with-variables/ 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 Link to comment https://forums.phpfreaks.com/topic/81935-using-a-php-function-to-make-a-viable-file-name-with-variables/#findComment-416279 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. Link to comment https://forums.phpfreaks.com/topic/81935-using-a-php-function-to-make-a-viable-file-name-with-variables/#findComment-416287 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. Link to comment https://forums.phpfreaks.com/topic/81935-using-a-php-function-to-make-a-viable-file-name-with-variables/#findComment-416291 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? Link to comment https://forums.phpfreaks.com/topic/81935-using-a-php-function-to-make-a-viable-file-name-with-variables/#findComment-416293 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? Link to comment https://forums.phpfreaks.com/topic/81935-using-a-php-function-to-make-a-viable-file-name-with-variables/#findComment-416315 Share on other sites More sharing options...
The Little Guy Posted December 16, 2007 Share Posted December 16, 2007 yes Link to comment https://forums.phpfreaks.com/topic/81935-using-a-php-function-to-make-a-viable-file-name-with-variables/#findComment-416317 Share on other sites More sharing options...
woocha Posted December 16, 2007 Author Share Posted December 16, 2007 yes Thanks dude Link to comment https://forums.phpfreaks.com/topic/81935-using-a-php-function-to-make-a-viable-file-name-with-variables/#findComment-416324 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.