Re: function to check variable name?

From: Date: Thu, 04 Feb 1999 03:46:08 +0000
Subject: Re: function to check variable name?
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-3875@lists.php.net to get a copy of this message
Andrey Zmievski writes: > Is there a function in PHP to check if a given string constitutes a valid > variable name? If not, what would be the best way to check it? > > -Andrey There isn't, but a simple basis for a test would be to check whether it matches PHP's rules using ereg(): function valid_name( $string ) { return ereg( "^[[:alpha:]_]{1}[[:alnum:]_]*$", $string ); } There may be a string length issue as well; I don't recall right now. Anyway, the above is from memory, and in my memory, a PHP variable name may be a letter or underscore followed by letters, numbers, or underscores. Torben -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#3875) next »