Re: Help Formatting String into URL
| From: | Frank Voorburg | Date: | Sat, 10 Jul 2004 13:59:06 +0000 |
| Subject: | Re: Help Formatting String into URL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-190130@lists.php.net to get a copy of this message | ||
Ryan,
You can use the following function:
function FormatUrl($url)
{
if (eregi("www", $url))
$result = "http://$url";
else
$result = "http://www.$url";
return $result;
}
You can test it using:
$test1 = FormatUrl("google.com");
$test2 = FormatUrl("www.google.com");
print "test1 = $test1<br>";
print "test2 = $test2<br>";
And this will give you the results:
test1 = http://www.google.com
test2 = http://www.google.com
Good luck!
-Frank
"Ryan Schefke" <ryan@triomfgroup.com> wrote in message
news:auto-000692835048@front3.chartermi.net...
> Hi,
>
>
>
> Can someone help me write a short code snippet to format a string to add:
>
>
>
> http://www <http://www/>
> -- if the string is "google.com" and doesn't
have
> http://www <http://www/>
> in front of it
>
>
>
> http:// <http://www/>
> -- if the string is "www.google.com" and doesn't
> have http:// in front of it
>
>
>
> .if you know of a better way to securely check/format a url like this
please
> let me know.
>
>
>
> Thanks,
>
> Ryan
>
>
>
>