Kevin Kevin - 1 year ago 90
PHP Question

replace different parts of string with php

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download