Skip to content

Instantly share code, notes, and snippets.

@esedic
Created June 7, 2014 08:20
Show Gist options
  • Save esedic/1c4a6b8daaf7a34210a6 to your computer and use it in GitHub Desktop.
Save esedic/1c4a6b8daaf7a34210a6 to your computer and use it in GitHub Desktop.
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'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment