i’ve a problem with a switch and a preg_match case
my code is like this
switch( $WORD ){
case ( preg_match("/^(?:.+-)?(\d+?)$/i", $WORD , $ID ) ? true : false ):
echo "valid ". $ID ." test -> " .preg_match("/^(?:.+-)?(\d+?)$/i", $WORD );
break;
default:
echo $WORD;
break;
}
these code work well with
$WORD = "TEST"; print => TEST
$WORD = "TEST-1"; print => valid 1 test -> 1
$WORD = "TEST-2552"; print => valid 2552 test -> 1
$WORD = "343"; print => valid 343 test -> 1
but if $WORD is null or $WORD = "" the case is true too and it print
$WORD = ""; print => valid test -> 0
how i can fix it?
i’ve tried with
case ( ( preg_match("/^(?:.+-)?(\d+?)$/i", $WORD , $ID ) == 1 ) ? true : false ):
but dosne’t work
i’ve resolved it with a simple trick so if some one have the same problem that is a way to resolve it … ( at the moment i don’t know if exist a better way )
Just before the case with
preg_matchadd a case likecase "":