Ciao.
Qualcuno mi sa dire come mai
questo codice non funziona
o meglio funziona nei metodi normali
ma non con input_var.
Lo scopo è di validare una stringa
passata all'url tramite urlencode
via get.
Per intenderci
Publicità e progresso
alfanumerica maiuscole e minuscole
e
_ - % +
Codice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Test</title>
</head>
<body>
<?php
$pattern= '#^[%_\-\+a-zA-Z0-9\/]+$#';
if(filter_has_var(INPUT_GET, 'qs')){
$options= array('options'=>array('regexp'=>$pattern));
$string=filter_input(INPUT_GET, 'qs', FILTER_VALIDATE_REGEXP, $options);
if($string===false){
echo "A filter GET match was not found.
";
}
else{
echo "A filter GET match was found.{$string}
";
}
}
if(isset($_GET['qs'])){
$string= urlencode($_GET['qs']);
if (preg_match($pattern, $string)) {
echo "A GET match was found.{$string}
";
} else {
echo "A GET match was not found.
";
}
}
$string= urlencode('bicycles multi byte chars èòàù');
if (preg_match($pattern, $string)) {
echo "A match was found.{$string}
";
} else {
echo "A match was not found.
";
}
?>
[url="<?php echo $_SERVER['PHP_SELF'].'?qs=bicycle_-%'; ?>"]test1[/url]
[url="<?php echo $_SERVER['PHP_SELF'].'?qs=bicycle_-%+'; ?>"]test2[/url]
[url="<?php echo $_SERVER['PHP_SELF'].'?qs='.urlencode('bicycles multi byte chars èòàù#'); ?>"]test2[/url]
</body>
</html>