Re: Strings and Characters therein
| From: | Richard Lynch | Date: | Wed, 06 Dec 2000 02:48:20 +0000 |
| Subject: | Re: Strings and Characters therein | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28820@lists.php.net to get a copy of this message | ||
>so when is a value contained in a string an integer rather than a
character?
Never. GetType() returns the underlying data type that the variable is
marked with.
> and can i convert from character to integer?
Yes.
Several different ways.
You can use something like:
$foo = (int) $bar;
which will convert all characters from the 0th character through the first
non-integer character to integer. A leading negative sign (aka "dash") is
also supported. Samples:
(int) "56K" ==> 56
(int) "-10 degrees" ==> -10
(int) "Pennsylvania 6500" ==> 0 (actually, I think it might return false,
or...)
In your case, an ereg_replace() or preg_replace() call would probably be
more suitable. If I knew Regexp better I'd give samples, but I don't so I
won't, but http://php.net has them.
And, of course, your routine will also work, though perhaps not quite as
fast nor as understandable to other programmers as ereg_replace. (OTOH, I
can read your code, and can never figure out Regexp, but that's just me...)
> is all data recieved from HTML forms considered to be a text string?
Yes. This is probably in the FAQ somewhere...