I am having a problem with this code:
$myvariable = "<?php $user_id = '5'; ?>";
…now I then write it to file using php…
and this is what I see when I open the saved file:
<?php = '5'; ?>
$user_id is missing!
Why is this happening and is there a way to fix this problem?
When you use double-quotes, any
$variablesin the text will be replaced with their current value. Because$user_idisn’t defined in the code that’s currently running, it’s replaced with nothing.There are a couple of ways to prevent this from happening. You could wrap your string in single-quotes instead, escaping the existing single-quotes in the text with a backslash:
Or you cou could instead escape the
$with a backslash, so that it’s not interpreted: