[Solved] Save a ” with variable in a text file php


I want to save “$my variable” in the file

If I understand you correctly, you want the resulting output to include quotes? You’d need to include the quotes in the value being saved. Perhaps something like this:

file_put_contents("mytext.txt","\"$variable\"");

or:

file_put_contents("mytext.txt",'"' . $variable . '"');

The difference is mostly a matter of personal coding style preference. Qouble-quoted strings expand variables, but your double-quotes would need to be escaped. Single-quoted strings wouldn’t need to escape the double-quotes, but don’t expand variables.

A string value doesn’t include quotes, it’s denoted to the compiler/interpreter/etc. by quotes. For the value itself to output quotes they need to be added to the value.

0

solved Save a ” with variable in a text file php