Problem with parse_url

I just tried to use “parse_URL” to extract the host, just as a simple way of cleaning up URLs.

It works, but if there is more than one failed submission of the form due to other errors, the website field is empty when the form is redisplayed for the second time. On the first redisplay, I can see the parse URL function in action, but after any other error, the data is lost.

The gist of my code is:

$_POST['domain'] = parse_url($_POST['domain'], PHP_URL_HOST);
// tidy other fields (e.g. trim and htmlspecialchars)
// validate all fields with regexes and create error messages if needed
// return form with error messages and data

I’m still fairly novice at PHP, with patchy knowledge of it.

Don’t assign it back to $_POST.

I wouldn’t know of any way of handling it if it went into a new array (See the last sentence of my first post). I have tried that kind of thing before for an unrelated reason and got waaay out of my depth. Completely screwed it up in the process and went back to what worked.

Anyway, I think that I’ve solved it by putting it into an if thingie and checking for the http/ftp/etc. Seems to work OK now.