Jump to content

Removing Particular Text From Field - PHP - HELP!


oliverj777

Recommended Posts

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!!

Link to comment
Share on other sites

I would test this but my FTP application keeps crashing  :confused: :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

Link to comment
Share on other sites

I would test this but my FTP application keeps crashing  :confused: :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.

Link to comment
Share on other sites

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.

 

 

 

 

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.