RE: [PHP] Regular expression - URL validator
| From: | Wagner Garcia Campagner | Date: | Wed, 29 Aug 2007 15:40:56 +0000 |
| Subject: | RE: [PHP] Regular expression - URL validator | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-261456@lists.php.net to get a copy of this message | ||
Thanks again Jim,
That's what i really need.
I'm testing this function...
If i put a URL like www.example.com, then it works fine and turns it to
http://www.example.com
But if i put a URL like http://www.example.com, then it also
put another
header so it turns to http://http://www.example.com
I also tried with the strstr function, but receive the same response.
Thanks in advance,
Wagner.
-----Original Message-----
From: Jim Lucas [mailto:lists@cmsws.com]
Sent: terça-feira, 28 de agosto de 2007 18:35
To: wagnergc@itautec.com
Cc: PHP General
Subject: Re: [PHP] Regular expression - URL validator
Wagner Garcia Campagner wrote:
> Thanks Jim,
>
> Your sugestion worked perfect for me!!
>
> I have another question:
>
> After i validate this URL i want to put a link with this URL in my page.
>
> The problem is that if the URL is like (www.aol.com), when i create the
> link, this URL is appended with the URL of my site. The result is a link
> pointing to: http://<mywebsite>/www.aol.com
>
> But if the URL is like (http://aol.com), then the link is created correct.
>
> Is there a way to avoid the first situation... so the link is created
> correct?
>
> Thanks again,
> Wagner.
>
You could always do a string comparison for http(s)? in the url
if ( strpos($url, array('https://', 'http://')) === false ) {
$url = 'http://'.$url;
}
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare