substr?
| From: | Chris Knipe | Date: | Mon, 17 Jun 2002 08:28:14 +0000 |
| Subject: | substr? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-102549@lists.php.net to get a copy of this message | ||
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?