oliverj777 Posted August 20, 2010 Share Posted August 20, 2010 Hello, I have a field in which when a user types something into it, it saves it into a table in my SQL. But is it possible to remove a particular phrase from the field if the user enters it. Example: I have a text field that says 'please enter your website domain here'. The user then enters 'www.domain.com'. Is it possible for PHP to remove the 'www.' and only save the 'domain.com' to my SQL (bearing in mind that not all users may enter www.) Here is the code for the text field: <input name="website_name" type="text" class="text-box" id="website_name" value="<?php echo $website_name; ?>" size="24" /> Here is the code for the _POST: if(isset($_POST['send'])) { $database->updateUserField($session->username, "website_name", $_POST['website_name']); } (the code so far all works fine - I just want to add an extra 'variable', if you will, to the code) Thanks for your help!! Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 20, 2010 Share Posted August 20, 2010 $website_name = str_replace('www.', '', $_POST['website_name']); Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted August 20, 2010 Author Share Posted August 20, 2010 I would test this but my FTP application keeps crashing :confused: -- It looks like it would work. For future reference, would that code search any text for 'www.' For example, if some user types in 'hellowww.' will that code also remove the 'www.' no matter where it is within the text, thus saving it as 'hello'? Thanks Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 20, 2010 Share Posted August 20, 2010 I would test this but my FTP application keeps crashing :confused: -- It looks like it would work. For future reference, would that code search any text for 'www.' For example, if some user types in 'hellowww.' will that code also remove the 'www.' no matter where it is within the text, thus saving it as 'hello'? Thanks Yes. Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted August 20, 2010 Author Share Posted August 20, 2010 I tested it - and it didn't work -- any suggestions? It still saves the www. into my SQL table?? Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted August 20, 2010 Author Share Posted August 20, 2010 This is my code so far: if(isset($_POST['send'])) { $website_name = str_replace('www.', '', $_POST['']); $database->updateUserField($session->username, "website_name", $_POST['website_name']); Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 20, 2010 Share Posted August 20, 2010 Well, you'll either need to change: $website_name = str_replace('www.', '', $_POST['website_name']); // to $_POST['website_name'] = str_replace('www.', '', $_POST['website_name']); Or change: $database->updateUserField($session->username, "website_name", $_POST['website_name']); // to $database->updateUserField($session->username, "website_name", $website_name); One or the other. Thought that would be obvious, sorry. Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted August 20, 2010 Author Share Posted August 20, 2010 sweet -- I used the $_POST['website_name'] = str_replace('www.', '', $_POST['website_name']); works fine 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.