-3

I try to store a string to a PHP variable. But it shows an error "Parse error: syntax error, unexpected '='" Here is the code

$page-title = "Home Page";

5 Answers5

0

Do like this:

$page_title = "Home Page";
Virb
  • 1,639
  • 1
  • 16
  • 25
0

Replace $page-title = "Home Page";

with: $page_title = "Home Page";

The variable you used is wrong. PHP variables cant contain - signs.

Red
  • 6,599
  • 9
  • 43
  • 85
0

Your variable name is incorrect.

A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).

Devsi Odedra
  • 5,244
  • 1
  • 23
  • 37
  • You should be write as comment, not by an answer. – Virb Aug 29 '16 at 09:14
  • PHP variables can contain a bit more than alpha-numeric characters, see: http://php.net/manual/en/language.variables.basics.php . But it is correct, that the OP's variable name is invalid due to the minus sign in it. – Rizier123 Aug 29 '16 at 09:16
0

You can use it either $pageTitle or $page_title as your variable name fore more detail refer php manual

Mohamed Nizar
  • 780
  • 9
  • 30
0

you have use - subtraction sign in declaring variable that's why it cause an error you can check here how to declare php variableshow to declare php variables

try this

$page_title = "Home Page";
Masroor_Shah
  • 303
  • 1
  • 15