Visualizzazione dei risultati da 1 a 5 su 5

Discussione: Funzione sbagliata

  1. #1
    Utente di HTML.it L'avatar di P4n1c
    Registrato dal
    Feb 2008
    Messaggi
    116

    Funzione sbagliata

    Codice PHP:
    function block_char ($name)
    {
        
        
    $block_char  strstr($name'<') ? FALSE '';
        
    $block_char .= strstr($name'>') ? FALSE '';
        
    $block_char .= strstr($name'"') ? FALSE '';
        
    $block_char .= strstr($name"'") ? FALSE '';
        
    $block_char .= strstr($name'$') ? FALSE '';
        
    $block_char .= strstr($name'(') ? FALSE '';
        
    $block_char .= strstr($name')') ? FALSE '';
        
    $block_char .= strstr($name';') ? FALSE '';
        
            if ( 
    $block_char == '' )
        {
        
            return 
    TRUE;
        
        } else {
        
            return 
    FALSE;
        
        }

    $a '>';
    if ( 
    block_char($a) )
    {
    print 
    1;
    } else {
    print 
    2;

    Per quale motivo stampa 1 ?
    Grazie in anticipo

  2. #2
    Utente di HTML.it L'avatar di P4n1c
    Registrato dal
    Feb 2008
    Messaggi
    116
    scusate se non modifico ma sono passati 60 minuti.

    Codice PHP:
    function block_char ($name)
    {
        
        
    $block_char  strstr($name'<') ? FALSE '';
        
    $block_char .= strstr($name'>') ? FALSE '';
        
    $block_char .= strstr($name'"') ? FALSE '';
        
    $block_char .= strstr($name"'") ? FALSE '';
        
    $block_char .= strstr($name'$') ? FALSE '';
        
    $block_char .= strstr($name'(') ? FALSE '';
        
    $block_char .= strstr($name')') ? FALSE '';
        
    $block_char .= strstr($name';') ? FALSE '';
        
            if ( 
    $block_char == '' )
        {
        
            return 
    TRUE;
        
        } else {
        
            return 
    FALSE;
        
        }
    }
    $a '>';
    if ( 
    block_char($a) )
    {
    print 
    1;
    } else {
    print 
    2;


  3. #3
    Qual'è l'utilità di quella funzione??

    http://it.php.net/manual/it/function.strstr.php leggiti cosa serve la funzione strstr()..
    Questa volta, più che un voto.. è favoreggiamento.

  4. #4
    Utente di HTML.it L'avatar di P4n1c
    Registrato dal
    Feb 2008
    Messaggi
    116
    Restituisce la parte della stringa haystack dalla prima occorrenza di needle fino alla fine di haystack .

    Se non si trova needle , restituisce FALSE.
    Quindi la uso semplicemente per verificare se c'è uno di quei caratteri, e invece di usare quello avrei potuto usare substr o stristr ecc...
    Es :


    Codice PHP:
    $var 'valore';

    if ( 
    strstr($var'v') ) // restituisce TRUE perchè la stringa V esiste.
    {
    echo 
    'ver';
    } else {
    echo 
    'falso';

    Quindi con quella fuzione il mio scopo è quello di verificare se in una stringa ci sono quei caratteri, e in caso ci fossero restituisce un valore falso ( return false ), e se non ci fossero dovrebbe, ma così non è, restituire un valore vero ( return true ).

    EDIT :
    Perfetto... ho capito dove sbagliavo
    Ora la funzione va a meraviglia ^^

  5. #5


    Codice PHP:
    function block_char ($name) {
        
        
    $valori  = array('<''>''"'"'"'$''('')'';');
        foreach (
    $valori AS $v) {
             if (
    strstr($name$v)) {
                return 
    FALSE;
             }
             return 
    TRUE;
        }

    Questa volta, più che un voto.. è favoreggiamento.

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.