-1

What I want to achieve: I want to use a simple PHP form to send data to a MySQL database. However, when the input contains a certain string, I want to remove it before it is saved in the MySQL database.

Example: input is 'https://www.google.com', but I want to remove the 'https://' part, so only 'www.google.com' is saved in the database.

Sam M
  • 4,136
  • 4
  • 29
  • 42
JamesM
  • 101
  • 2
  • 3
  • 11
  • 1
    http://php.net/manual/en/function.str-replace.php but for URLs maybe http://php.net/manual/en/function.parse-url.php – AbraCadaver Feb 12 '18 at 20:54

1 Answers1

1

You can use str_replace() to remove the parts you don't want:

$input = 'https://www.google.com';
$replaced = str_replace('https://', '', $input);

echo $replaced;

If you want to replace multiple values in one pass, you also do that (this will remove http://, https:// and ftp://):

$unwanted  = array("http://", "https://", "ftp://");
$replace   = array("", "", "");

$replaced = str_replace($unwanted, $replace, $input);

See: https://secure.php.net/manual/en/function.str-replace.php

rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38