I have a form in which users can input a URL. Now obviously they some will put in http://www.example.com/path or example.com/path or http://www.example.com/path or even http://example.com/path.
What I want to do is to extract the whole URL host and path ect.. and put it in a standard form into my database. So no matter how it is formatted in the input they all have the same formatting in the database.
so the inputs go to outputs like below
www.example.com/path -> http://www.example.com/path
example.com/path -> http://www.example.com/path
http://www.example.com/path -> http://www.example.com/path
http://example.com/path ->http://www.example.com/path
Use regex for the URL’s then use preg_match when validating it and specify PREG_OFFSET_CAPTURE to make it into an array of the values in the matches. Then manipulate it to a string that satisfies your format.