esedic
6/7/2014 - 8:20 AM

Prepend http to a URL

Prepend http to a URL

<?php

//Some times you need to accept some url as input but users seldom add
// http:// to it, this code will add http:// to the URL if it’s not there.

if (!preg_match("/^(http|ftp):/", $_POST['url'])) {
   $_POST['url'] = 'http://'.$_POST['url'];
}