xxxxxxxxxx
<?php
/* In PHP, a variable starts with the $ sign,
followed by the name of the variable:
*/
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
xxxxxxxxxx
<?php
# To declare variables in php, you should prefix the variable name with
# a dollar sign and assign it the value. For example:
$msg = 'Hello World';
$number = 10;
$decimal = 98.6;
$result = true;
# To print out variable names, you can directly enter the variable name
# inside of a print or echo statement. For example:
echo "Variables: $msg, $number, $decimal, $result"
?>
xxxxxxxxxx
## 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);
[]