Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    input_var regex urlencode

    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'])){
        
    $stringurlencode($_GET['qs']);
        if (
    preg_match($pattern$string)) {
            echo 
    "A GET match was found.{$string}
    "
    ;
        } else {
            echo 
    "A GET match was not found.
    "
    ;
        }        
    }

    $stringurlencode('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>
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  2. #2
    hmm. mi non sono un esperto di il regexp cmq vorrai il questo?

    Codice PHP:
    $pattern'^([a-z-A-Z]?[0-9])$^'
    o ti vogli fare qualcosa altra?

    Ciao!
    Dennis M.
    Nuovo Blog di Programmazione! (Lo ha i tutti tipi! PHP e C/C++)
    Per piacere lo supporti!

  3. #3
    Originariamente inviato da DennisM
    hmm. mi non sono un esperto di il regexp cmq vorrai il questo?

    Codice PHP:
    $pattern'^([a-z-A-Z]?[0-9])$^'
    o ti vogli fare qualcosa altra?

    Ciao!
    Dennis M.
    Thanks for your help
    but you should read better
    what I'm looking for ............

    La regex con i metodi tradizionali funziona
    non funziona solamentte con filter_var


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  4. #4
    oh mi dispiace.

    beh hai:

    Codice PHP:
    [url="<?php echo $_SERVER['PHP_SELF'].'?qs=bicycle_-%+'?>"]test2[/url]


    [url="<?php echo $_SERVER['PHP_SELF'].'?qs='.urlencode('bicycles multi byte chars  èòàù#'); ?>"]test2[/url]
    se non ti vogli loro a fare poi:

    Codice PHP:
    $pattern'#^[%_\\-a-zA-Z0-9]+$#'
    ma in ogni caso si ricevi un errore perche non hai "sfugato" - con un \.

    ma il questo va bene per tutto (il tuo $pattern con un \)

    Codice PHP:
    $pattern'#^[%_\\-+a-zA-Z0-9/]+$#'
    Ciao!
    Nuovo Blog di Programmazione! (Lo ha i tutti tipi! PHP e C/C++)
    Per piacere lo supporti!

  5. #5
    In un selettore di character class, il trattino (dash '-') puo' essere solo il primo o l'ultimo carattere (quando vuoi cercare il dash e non lo usi come operatore di range).

    Scusa la curiosita', ma perche' scrivi in versi?

  6. #6
    Codice PHP:
    <?php 
    $pattern
    '#^[- _%a-zA-Z0-9/]+$#'
    // IT DOESN'T WORK 
    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}
    "

        } 
    }    
    ?>
    i + non sono da considerare
    l'input non è più urlencoded
    al momento della validazione.

    adesso funziona con gli spazi
    ma non con le string multi bytes.

    il pattern è questo

    $pattern= '#^[- _%a-zA-Z0-9/]+$#';

    con questa funziona

    $pattern= '#^[- _a-zA-Z0-9\/òàùè]+$#';

    ma si accettano consigli




    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  7. #7
    Cambio tattica

    Codice PHP:
    function sanatizeString($string){ 
            
    $dodgychars"#[^0-9a-zA-Z]#"
            return 
    preg_replace($dodgychars,"-",$string); 
        } 
        
    var_dump(sanatizeString("Publicità e progresso")); 

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.