That's odd ... the code I gave you I tested prior to pasting into my
email, and it worked fine ... and still does.  I'm not aware of any bugs
with logical "or" in any versions of PHP.  If this doesn't work for you,
I'm not sure where to go.  (It works on my server  ... PHP 4.0.6-5 ...
and my personal preference for "||" over "or" is reflected :)

<?php
        $sString = "foo-";
        if( substr( $sString, 0, 1 ) != "-" ){
                print( "no - at beginning of string<br>" );
        }

        if( substr( $sString, -1, 1 ) != "-" ){
                print( "no - at end of string<br>" );
        }

        if( ( substr( $sString, 0, 1 ) != "-" ) ||
            ( substr( $sString, -1, 1 ) != "-" ) ){
                print( "- missing from beginning or end of string<br>" );
        }
?>

        g.luck,
        ~Chris                           /"\
                                         \ /     September 11, 2001
                                          X      We Are All New Yorkers
                                         / \     rm -rf /bin/laden

On Sun, 21 Oct 2001, Brad Melendy wrote:

> Thanks Chrisopher,
> Yeah, I was a tad confused.  What I wanted to say in my statement was really
> this:
>
> if ((substr($sString,-1,1)!="-") or (substr($sString,0,1)!="-")) {
> print "do this if there isn't a dash at the beginning or end of your
> string";
> }
> else {
> print "you can't have a dash at the beginning or end of your string.";
> }
>
> I like the simplifying of the statement by counting backwards regardless of
> the string length.  But I still can't get the darn thing to work if I use:
>
> if ((substr($sString,-1,1)!="-") or (substr($sString,0,1)!="-"))
>
> It only works if I use (substr($sString,-1,1)!="-") or
> (substr($sString,0,1)!="-") by themselves.  That only catches one half of
> what I am trying to do though.  I get the results I expect indivitually so
> that "-hello" fails with one part of the statement and "hello-" fails with
> the other part, but when I use them together with the OR operator, it
> doesn't pick up either case, "-hello" or "hello-".
>
> I think I'm going to have to resort to evaluating the string with more than
> just the one IF statement and use an ELSEIF and duplicate some code to make
> this work.  Thanks very much in advance.
>
> ....Brad
>
> "Christopher William Wesley" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > 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: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
>
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to