php: Add http:// if not entered in a form
Posted: Wed Dec 03, 2003 12:24 pm
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]
<?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]