Jump to content

Using a PHP function to make a viable file name with variables


woocha

Recommended Posts

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

$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?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.