Hi Frank,

Thanks, you got me started. I modified your function a bit.  I'm testing for
3 cases now and the appearance of http://, https://, or ftp:// in front of
the string.  Let me know if you advise any changes.

<?php 
function FormatUrl($url)
{
  $url = trim($url);
  if (eregi("^(((http)|(https)|(ftp)){1}://)", $url)) {
    $result = "$url"; // do nothing
        } else if (eregi("^www\.{1}", $url)) {
           $result = "http://$url";;
           } else {
                        $result = "http://www.$url";;            
                        }
 return $result;
}
?>
-----Original Message-----
From: Frank Voorburg [mailto:[EMAIL PROTECTED] 
Sent: Saturday, July 10, 2004 9:59 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: Help Formatting String into URL

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" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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
>
>
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to