Re: String valid?
| From: | Daniel R. Anderson | Date: | Mon, 21 Apr 2003 06:24:11 +0000 |
| Subject: | Re: String valid? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144606@lists.php.net to get a copy of this message | ||
You could try something like this:
function is_string_a_number($string)
{
$fff = fopen('temp','w'); // I'm sorry but I like I/O .. :-P
fwrite($fff,$string);
fclose($fff);
$fff = fopen('temp','r');
while ($fff and (!(feof($fff))))
{
$a_char = fgetc($fff);
if (!(($a_char == '1') or ($a_char == '2') or ($a_char == '3') or
($a_char == '4') or ($a_char == '5') or ($a_char == '6') or
($a_char == '7') or ($a_char == '8') or ($a_char == '9') or
($a_char == '0') or ($a_char == '.')))
{
return FALSE;
}
};
return TRUE;
}
I'm a relative noob to PHP, and would love it if anybody can offer any
tips or advice as to why this code is good or bad. :-)
-Dan Anderson