Here is a set of functions that you can use to format, validate, and “clean up” URLs that come from user input, databases, or even variables.

Bitnami