PHP: Funzione Ereg

Di solito la funzione Ereg viene utilizzata per il riconoscimento di espressioni regolari, per esempio variabili di stringa e testi che possono incrociarsi. Nell’esempio potrete notare come una data in formato ISO sia trasformata nel classico 00/00/0000:

 
?
 
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $data, $regs)) {
    echo "$regs[3].$regs[2].$regs[1]";
} else {
    echo "Formato di data non valido: $data";
}
 
?

Articoli simili

  1. Posted febbraio 18, 2010 at 10:49 am

    Ecco altri esempi di utilizzo di ereg in PHP:

    /* Restituisce vero se “abc”
    viene trovata ovunque in $string. */
    ereg(“abc”, $string);

    /* Restituisce vero se “abc”
    viene trovata all’inizio di $string. */
    ereg(“^abc”, $string);

    /* Restituisce vero se “abc”
    viene trovata alla fine di $string. */
    ereg(“abc$”, $string);

    /* Restituisce vero se il browser
    è Netscape 2, 3 oppure MSIE 3. */
    eregi(“(ozilla.[23]|MSIE.3)”, $HTTP_USER_AGENT);

  2. Posted febbraio 18, 2010 at 10:50 am

    Visita http: danzisiweb [.] altervista . org

Lascia un commento

Your email is never published nor shared. Required fields are marked *

*
*

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 5 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a