RE: [PHP] substr?
| From: | Lazor, Ed | Date: | Mon, 17 Jun 2002 17:24:02 +0000 |
| Subject: | RE: [PHP] substr? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-102551@lists.php.net to get a copy of this message | ||
> -----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.