Re: Using Logical OR operator in IF statement???

From: Date: Sun, 21 Oct 2001 07:08:59 +0000
Subject: Re: Using Logical OR operator in IF statement???
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-71721@lists.php.net to get a copy of this message
I'm a bit confused by the logic used (your conditionals are looking for NOT -, but then the printed statement indicates you were looking for the -), but anywho ... try these on for size. if (substr($sString,-1,1)=="-") { print "You can't have a dash at the end of your string."; } if (substr($sString,0,1)=="-") { print "You can't have a dash at the beginning of your string."; } if ((substr($sString,-1,1)=="-") or (substr($sString,0,1)=="-")) { print "you can't have a dash at the beginning or end of your string."; } (They reflect me thinking that you just had a logic mix-up, and I simplified the call to substr() ... the strlen() was overkill.) g.luck, ~Chris /"\ \ / September 11, 2001 X We Are All New Yorkers / \ rm -rf /bin/laden On Sat, 20 Oct 2001, Brad Melendy wrote: > Hello, > Ok, this works: > > if (substr($sString,(strlen($sString)-1)!="-")) { > print "You can't have a dash at the end of your string."; > } > > and this works: > if (substr($sString,0,1)!="-") { > print "You can't have a dash at the beginning of your string."; > } > > But, this doesn't work for any case: > if ((substr($sString,(strlen($sString)-1)!="-")) or > (substr($sString,0,1)!="-")) { > print "you can't have a dash at the beginning or end of your string."; > } > > What could be wrong? I've used a logical OR operator in the middle of an IF > statement like this before, but for some reason, this just isn't working. > Anyone got any ideas? I suppose I can just evaluate this with two different > IF statements, but it seems like I shoud be able to do it in one and reduce > duplicate code. Thanks very much in advance. > > .....Brad > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#71721) next »