Re: String valid?

From: Date: Mon, 21 Apr 2003 14:37:04 +0000
Subject: Re: String valid?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-144641@lists.php.net to get a copy of this message
ARGH! DO NOT USE THAT UNDER ANY CIRCUMSTANCES! Even forgetting the unneccesary overhead caused by using files for this, it would be possible for one user's file to be written at the same time as another's, causing problems. I would use preg_match('|^[0-9]+$|',$string) instead. Daniel R. Anderson wrote:
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
-- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.

« previous php.general (#144641) next »