Search code examples
phpfwrite

Variable not detected as variable


I wanted to ask, how I can write down a variable without it's getting detected as one.

As example:

$data = <<< DATA
<?php
$dbServername = $_POST["admin"];
?>
DATA;

$dbServername shouldn't be a variable, but $_POST["admin"]; should be one.

I want, to write with fwrite the $_POST["admin"] variable into a document. But when $dbServername also gets detected as a variable, but it should be one, it throws errors.

Any Idea how to fix this?

EDIT:

There are 2 ways:

Either escape them with a backslash \ or put the variable into curly brackets {}. That also works.


Solution

  • Either escape the dollar sign by adding a backslash (\) infront of the dollar sign, or use single quotes to denote the string.