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

Link to comment
Share on other sites

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.