Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php variable definition

## Regex:
## ^[a-zA-Z_x80-xff][a-zA-Z0-9_x80-xff]*$

// PHP validate variable name

$regex = '/^[a-zA-Z_x80-xff][a-zA-Z0-9_x80-xff]*$/i';

// Valid
preg_match($regex, '_aas', $matches);
[
    "_aas",
]

// Valid
preg_match($regex, '_validVariable', $matches);
[
    "_validVariable",
]

// Valid
preg_match($regex, 'oth3r_valid_variable', $matches);
[
    "oth3r_valid_variable",
]

//Invalid
preg_match($regex, 'invalid Variable', $matches);
[]

//Invalid
preg_match($regex, '0th3r_invalid_vriable', $matches);
[]

//Invalid
preg_match($regex, '0th3r_invalid_variable', $matches);
[]
Source by www.php.net #
 
PREVIOUS NEXT
Tagged: #php #variable #definition
ADD COMMENT
Topic
Name
4+2 =