1

I need to create PHP file by php script and i have to include variables in PHP file but but the problem is that when i am trying to add PHP varibale as a text(In double quotes) then it is still taking this as a variable please help me.

<?php
    $my_file = 'anas.php';
    $handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file);
    $data = "
    <?php   
    private class faraz
    {
        $name='anas';
    } 
    ?>";
    fwrite($handle, $data);
?>

Undefined variable: name in D:\xampp\htdocs\hawai\index.php on line 8

1 Answers1

2

Escape dollar sign, or use single quotes.

$data = "
    <?php   
    private class faraz
    {
        \$name='anas';
    } 
    ?>";

OR

$data = '
    <?php   
    private class faraz
    {
        $name="anas";
    } 
    ?>';
pavel
  • 26,538
  • 10
  • 45
  • 61