Prepend http to a URL


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. if (!preg_match("/^(http|ftp):/", $_POST['url'])) {
  2. $_POST['url'] = 'http://'.$_POST['url'];
  3. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.