Ciao a tutti, nel seguente codice ottengo un errore di sintassi.. dove sbaglio?
codice:$avvPrezzo = (strstr($prezzo, ',') === FALSE) && (!strstr($prezzo, '.') === FALSE) ? 'errore' : ''; echo $avvPrezzo;
Ciao a tutti, nel seguente codice ottengo un errore di sintassi.. dove sbaglio?
codice:$avvPrezzo = (strstr($prezzo, ',') === FALSE) && (!strstr($prezzo, '.') === FALSE) ? 'errore' : ''; echo $avvPrezzo;
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.
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?>