/    Sign up×
Community /Pin to ProfileBookmark

How to replace space " " with underscore "_"

I need a little help. I have created the below script. A form that save its info to my database and a long with that it create some (2 on different paths) folders on the server.

My issue is that in the form under ”folder” you can type the name of the folder you want to create along with the info that is saved in the database. At the moment everything works just as it should. My request/issue is how do a replace space “ “ from the folder name to an underscore “_”

Means, if someone enters a folder name called “My Folder Photo” I need the script to change the name to: “my_folder_photo” so it will work in urls on the website.

The is my codes so fare:

[code=php]<?php
include “../config.php”;
if(isset($_POST[‘send’]))
{
mysql_query(“insert into profiles set name= ‘”.$_POST[“name”].”‘, age= ‘”.$_POST[“age”].”‘, country = ‘”.$_POST[“country”].”‘, folder = ‘”.$_POST[“folder”].”‘”);

$folder = $_POST[‘folder’];
$path1 = ‘../game1/photos/’ . $folder;
$path2 = ‘../game2/photos/’ . $folder;
mkdir($path1);
mkdir($path2);
header(“Location: myprofile-new-step2.php”);

exit;
}

?>

<form method=”post” action=”<?=$_SERVER[“PHP_SELF”]?>” name=”myform” id=”myform”>
<table bgcolor=”#FFFFFF” border=”0″ align=”center”><tr><td width=”70″>
Name:
</td><td width=”270″>
<input type=”text” name=”name” size=”40″>
</td><td>

</td></tr><tr><td>
Age:
</td><td>
<input type=”text” name=”age” size=”40″>
</td><td>

</td></tr><tr><td>
Country:
</td><td>
<select name=”country” data-placeholder=”<?=$country?>” class=”chosen-select” style=”width:250px;” id=”<?=$country?>” value=”<?=$country?>” <?= (!empty($country) ? ‘checked=”checked”‘ : “”)?>>
<option value=”<?=$country?>”></option>
<option value=”United States”>United States</option>
<option value=”United Kingdom”>United Kingdom</option>
</select>
</td><td>
Enter the country you live in.
</td></tr><tr><td>
Folder:
</td><td>
<input type=”text” name=”folder” size=”40″ id=”folder”>
</td><td>

</td></tr></table>
<center><br />
<input type=”submit” name=”send” title=”NEXT” value=”NEXT”></center>
</form>[/code]

Im a new to php so need as much help as possible to figure this out ? THANKS

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 12.2014 — [code=php]
$name = str_replace(' ', '_', $name);
[/code]
Copy linkTweet thisAlerts:
@GertKauthorJan 12.2014 — Thx, endend up with this: $folder = str_replace(" ","_",strtolower($_POST['folder'])); and that Works. Thanks for your help ?
×

Success!

Help @GertK spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...