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

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

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.

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.

 

 

 

 

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.