RE: PHP preg_match() help

Hi,
I love all these new functions.  They make life a lot easier. *grin*
Except when I can't get them to work.  I wrote up a test script to see
if I understood how it works, and everything I type in validates.
Here's my test script.  Please let me know what's wrong with it.  One
final note, I used the FILTER_FLAG_HOST_REQUIRED flag because I want
every url to at least start with http://(hostname) anything else is
optional, like ?id=123 for example.
Thanks for the help, here's the code:
<?php
$tst = $_GET["uri"];
if (filter_var($tst, FILTER_SANITIZE_URL, FILTER_FLAG_HOST_REQUIRED))
{
echo "valid\n";
}
else
{
echo "not valid\n";
}
php?>
BlueScale
On Wed, 2008-07-30 at 12:07 -0400, Humberto Rodriguez wrote:
> Hello,
> 
>  
> 
> PHP 5.2 has new functions for this.  Use the function filter_var()
> with the filter called FILTER_SANITIZE_URL, as follows:
> 
>  
> 
> $var=filter_var($var, FILTER_SANITIZE_URL);
> 
>  
> 
> HTH,
> 
>  
> 
> Humberto
> 
>  
> 
>  
> 
>  
> 
> 
> From: programmingblind-bounce@xxxxxxxxxxxxx
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Storm
> Dragon
> Sent: Wednesday, July 30, 2008 2:50 AM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: PHP preg_match() help
> 
> 
> 
>  
> 
> Hi,
> I am having a bit of a problem. I was never good at the PHP
> preg_match() function.  I am working on a website for a client andI
> need to be able to accept anything except ; and space.  Well, actually
> I really need to make sure a url is in proper format.  The problem is,
> it could be any url and they can be so different.  I want to protect
> against sql injection attacks, so I figured getting rid of ; and space
> would go a log way toward that end.  I suppose no " or ' would be good
> too, I can't think of any urls with either of those in them, but it's
> late and I am tired, so can't be sure.
> Thanks for any help.
> BlueScale
> 
> 

Other related posts: