Re: substr?
| From: | Chris Knipe | Date: | Mon, 17 Jun 2002 18:29:33 +0000 |
| Subject: | Re: substr? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-102559@lists.php.net to get a copy of this message | ||
Thanks,
I don't know *what* I was thinking.... The if statement still returns false
though...
// Validate cell if we have one.
if (!$_POST['NumC'] == "") {
if ((substr($_POST['NumC'], 0, 3) != "082") OR
(substr($_POST['NumC'],
0, 3) != "072") OR
(substr($_POST['NumC'], 0, 3) != "083") OR
(substr($_POST['NumC'],
0, 3) != "073") OR
(substr($_POST['NumC'], 0, 3) != "084")) {
Any number passes. For example, if I have 123 as the first three chars, it
passes... I fail to see how it manages this??
----- Original Message -----
From: "Lazor, Ed" <ELazor@providence.org>
To: "'Chris Knipe'" <savage@savage.za.org>;
<php-general@lists.php.net>
Sent: Monday, June 17, 2002 7:24 PM
Subject: RE: [PHP] substr?
>
>
> > -----Original Message-----
> > Is this right? It seems to me that substr is working in reverse?
>
> Reverse... that's what the -7 specifies.
>
> substr($string, 0, -7)
>
> is
>
> 123
>
> You could also do
>
> substr($string, 0, 3)
>
> to get the same thing.
>
>
> >
> > $string = "1234567890"; // Always numerical, always 10 chars.
> > if (!substr($string, 0, -7) == "083") {
> > echo "not 083\n";
> > } else {
> > // Exists here.
> > echo "is 083\n";
> > }
> >
> > Due to the reverse if, shouldn't it exit not 083? I'd just like
> > to get some clarity on this, allot of my work depends on
> > validating these
> > numbers *correctly*.... Basically, I want to see if the first three
> > characters is 072, 073, 082, 083, or 084. If not, the $string must be
> > discarded.
> >
> > I've also tried if(substr($string, 0, -7) != "083"), but that
> > also doesn't
> > work.... ereg(*) also doesn't seem to be able to search for
> > patterns only on
> > the beginning of a string, so even if I wanted to use a ereg
> > expression, I'd
> > have to cut the first 3 chars from the string with substr first?
> >
> > How can / should I validate these numbers?
> >
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
****************************************************************************
> This message is intended for the sole use of the individual and entity to
> whom it is addressed, and may contain information that is privileged,
> confidential and exempt from disclosure under applicable law. If you are
> not the intended addressee, nor authorized to receive for the intended
> addressee, you are hereby notified that you may not use, copy, disclose or
> distribute to anyone the message or any information contained in the
> message. If you have received this message in error, please immediately
> advise the sender by reply email and delete the message. Thank you very
> much.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>