Re: substr?
| From: | Adam Voigt | Date: | Mon, 17 Jun 2002 17:23:50 +0000 |
| Subject: | Re: substr? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-102550@lists.php.net to get a copy of this message | ||
I'm confused, are you trying to compare the first three characters of
the string? If you are I think what you want is:
substr($string,0,3);
Adam Voigt
adam.voigt@cryptocomm.com
On Mon, 2002-06-17 at 04:28, Chris Knipe wrote:
> Hi all,
>
> Is this right? It seems to me that substr is working in reverse?
>
> $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
>