Wagner Garcia Campagner wrote:
> Hello,
>
> I found this regular expression on a web site.
> It is basicaly an URL validator.
>
> I'm trying to implement this in my web site, but i receive errors.
>
> I think this is a PERL REGEX so what should i do to make it work in php?
>
>
> $valid =
> (preg_match('^((((H|h)(T|t)|(F|f))(T|t)(P|p)((S|s)?))\://)?(www.|[a-zA-Z0-9]
> .)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]{1,5})*(/($|[a-zA-Z0-9\.\,\;\?\'\\\
> +&%\$#\=~_\-]+))*$', $_POST['website']));
This should be preg_match('/.../i', $_POST['website'])
your regex should look something like this.
^((ftp|(http(s)?))://)?(\.?([a-z0-9-]+))+\.[a-z]{2,6}(:[0-9]{1,5})?(/[a-zA-Z0-9.,;\?|\'+&%\$#=~_-]+)*$
So, put it all together and it should look like this.
<?php
$url = "...PUT YOUR TEST URL HERE...";
if (
preg_match('!^((ftp|(http(s)?))://)?(\.?([a-z0-9-]+))+\.[a-z]{2,6}(:[0-9]{1,5})?(/[a-zA-Z0-9.,;\?|\'+&%\$#=~_-]+)*$!i',
$url) ) {
echo "Matched";
} else {
echo "Did not match";
}
>
> if ($valido == 0) {
> something here;
> }
> else {
> something else here;
> }
>
>
> Thanks a lot in advance,
> Wagner.
>
--
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php