-5

i want to echo a div in PHP, and set the ID equal to the value of $divName, but i cannot get it to work

Here is my code:

$divName = "divText"
echo '<div id=$divName></div>'
igetstuckalot
  • 237
  • 2
  • 8
  • 16
  • 4
    Variables are not interpolated in single quotes. Basic php. – John Conde Jul 26 '16 at 23:15
  • you should study more the basics about PHP like how to echo: http://php.net/manual/en/function.echo.php Follow some tutorials for starters first – CDrosos Jul 26 '16 at 23:16
  • Possible duplicate of [What is the difference between single-quoted and double-quoted strings in PHP?](http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – andrewsi Jul 27 '16 at 02:17

2 Answers2

3

Just do it like this:

$divName = "divText";
echo '<div id="'.$divName.'"></div>';

You should read the PHP Documentation. This is really basic stuff. http://php.net/docs.php

Marcel Wasilewski
  • 2,519
  • 1
  • 17
  • 34
0

Why you don't add semicolons (;) at the end of each command line?

Change single quotes (') to double quotes (") and that it:

$divName = "divText";
echo "<div id=$divName></div>";
Mr. Noob
  • 136
  • 1
  • 7