note 101978 added to language.variables.basics
| From: | maurizio dot domba at pu dot t-com dot hr | Date: | Fri, 21 Jan 2011 10:23:57 +0000 |
| Subject: | note 101978 added to language.variables.basics | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175959@lists.php.net to get a copy of this message | ||
If you need to check user entered value for a proper PHP variable naming convention you need to add
^ to the above regular expression so that the regular expression should be
'^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'.
Example
<?php
$name="20011aa";
if(!preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',$name))
echo $name.' is not a valid PHP variable name';
else
echo $name.' is valid PHP variable name';
?>
Outputs: 2011aa is valid PHP variable name
but
<?php
$name="20011aa";
if(!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',$name))
echo $name.' is not a valid PHP variable name';
else
echo $name.' is valid PHP variable name';
?>
Outputs: 2011aa is not a valid PHP variable name
----
Server IP: 69.147.83.197
Probable Submitter: 213.147.121.37
----
Manual Page -- http://www.php.net/manual/en/language.variables.basics.php
Edit -- https://master.php.net/note/edit/101978
Del: integrated -- https://master.php.net/note/delete/101978/integrated
Del: useless -- https://master.php.net/note/delete/101978/useless
Del: bad code -- https://master.php.net/note/delete/101978/bad+code
Del: spam -- https://master.php.net/note/delete/101978/spam
Del: non-english -- https://master.php.net/note/delete/101978/non-english
Del: in docs -- https://master.php.net/note/delete/101978/in+docs
Del: other reasons-- https://master.php.net/note/delete/101978
Reject -- https://master.php.net/note/reject/101978
Search -- https://master.php.net/manage/user-notes.php