I had a small problem with some websites lately, according to the databases, people started to fill in webaddresses without http:// and some with http:// so i coded the following to fix this.
[php]
<?php
$url = "www.yourdomain.net";
function CheckUrl($url)
{
$fls = substr($url,0,7);
$ucase_var = strtoupper($fls);
if($ucase_var != "HTTP://")
{
$url = "http://$url";
}
return($url);
}
$result = CheckUrl ($url);
echo $result;
?>[/php]
php: Add http:// if not entered in a form
Moderator: Moderators
-
- hit the ground hard, real hard
- Posts: 93
- Joined: Thu Jul 31, 2003 11:36 pm
- Location: fi
- Contact:
This is bit shorter version
[php]<?php
$url = "www.yourdomain.net";
function CheckUrl($url)
{
if (!preg_match("/http:\/\/\b/i",$url))
return "http://$url";
return $url;
}
echo CheckUrl($url);
?>[/php]
Edit: Removed one more line
[php]<?php
$url = "www.yourdomain.net";
function CheckUrl($url)
{
if (!preg_match("/http:\/\/\b/i",$url))
return "http://$url";
return $url;
}
echo CheckUrl($url);
?>[/php]
Edit: Removed one more line