Posted By

paulgrenwood on 09/23/09


Tagged

http php link


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

silentbob84
luman


Prepend http to a URL


 / Published in: 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.

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

Report this snippet  

You need to login to post a comment.