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

    operatore ternario e errore di sintassi

    Ciao a tutti, nel seguente codice ottengo un errore di sintassi.. dove sbaglio?

    codice:
    $avvPrezzo = (strstr($prezzo, ',') === FALSE) && (!strstr($prezzo, '.') === FALSE) ? 'errore' : '';
    
    echo $avvPrezzo;

  2. #2
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,452
    A me l'errore di sintassi non appare.

    Al limite prova a racchiudere entrambe le condizioni tra parentesi tonde, così
    $avvPrezzo = ( (strstr($prezzo, ',') === FALSE) && (!strstr($prezzo, '.') === FALSE) ) ? 'errore' : '';

    Comunque
    !strstr($prezzo, '.') === FALSE

    equivale a
    strstr($prezzo, '.') !== FALSE

    che è più leggibile.

  3. #3
    Puoi provare anche utilizzando strpos..

    Codice PHP:
    <?php$mystring '24,79€';$findme   ',';$pos strpos($mystring$findme);
    /* Notate l'uso di ===.  Il == non avrebbe risposto come atteso poiché la posizione di 'a' è nel primo carattere.*/if ($pos === false) {    echo "The string '$findme' was not found in the string '$mystring'";} else {    echo "The string '$findme' was found in the string '$mystring'";    echo " and exists at position $pos";}
    /* Ricerca di un carattere ignorando qualsiasi cosa prima di offset*/$newstring 'abcdef abcdef';$pos strpos($newstring'a'1); // $pos = 7, not 0?>

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 © 2024 vBulletin Solutions, Inc. All rights reserved.