0

I have a bit of php code that posts the value of a form field like this:

str_replace("www.", "", $_POST['billing_myfield12'])

This php code excludes the www part if the user entered it. I would like to exclude http and https aswell if this is entered as a value.

I tried doing something like this, but it didn't work:

str_replace("www."&&"http://", "", $_POST['billing_myfield12'])

any ideas on how to exlude multiple parts

Kevin
  • 930
  • 3
  • 13
  • 34

2 Answers2

1

You can do this:

$strToRemove= array("www","http","blabla");
$newStr = str_replace($strToRemove, "", $_POST['billing_myfield12']);

you put them in an array and then fed it to the str_replace function's first parameter.

Lorence Hernandez
  • 1,189
  • 12
  • 23
1

Like this:

str_replace(array("www","http://","https://"), '', $_POST['billing_myfield12']);

Or, in modern PHP (anything from 5.4 onwards), the slighty less wordy:

str_replace(["www","http://","https://"], '', $_POST['billing_myfield12']);
shubham715
  • 3,324
  • 1
  • 17
  • 27