0

I'm writing a php file that load data and save them to php file, every things works fine except when I'm trying to write a var (as var) into the file like:

$content="include 'pages/page1.html'; 
include 'pages/page2.html';";

$content.="$ChangingPage";
$content.="include 'pages/page3.html';;

I get error:

Notice: Undefined variable: ChangingPage in /MYHOST/pages/write_properties.php on line 75

I want the new php file to contain the ChangingPage as var ($)

2
  • The error looks pretty self-explanatory. You haven't defined $ChangingPage anywhere in your code, as far as I can tell. Also, I have no idea what are you trying to do with the $content variable declaration in the first line. Commented Oct 8, 2013 at 15:36
  • As I understand it, they are trying to output text that happens to be code and doesn't want it to execute Commented Oct 8, 2013 at 15:42

1 Answer 1

5

In php when you use quotes it will automatically use a variable when you use a dollar sign. It will also use the variable value when you use quotes and wrap the variable in { } brackets

To avoid this escape the dollar sign or switch to ' instead of "

$a = "text"; //text
$b = "$a"; //text
$c = "{$a}"; //text

$d = '$a'; //$a
$e = '{$a}'; //{$a}
$f = "\$a"; //$a
Sign up to request clarification or add additional context in comments.

2 Comments

or escape the dollar sign... " \$variablename "
I tried it and it works, but now my new php doesn't run, the script is good I've missing ; or something like ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.