-1

A have a variable with a -. When I run my script I get Parse error: syntax error, unexpected '='.

This is the following line:

$selected-text = $_POST['faco'] ;

How can I write this script without changing the variable name?

John
  • 904
  • 8
  • 22
  • 56

1 Answers1

0

The "-" character is a reserved operator in PHP and can't be used in variable names. Use an underscore instead:

`$selected_text = $_POST['faco'];`

In PHP a valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' (http://php.net/manual/en/language.variables.basics.php)

sg-
  • 2,196
  • 1
  • 15
  • 16