I want to create one folder say 'newfolder' and also want to create a file called 'index.php' in newfolder which should contain the code I specified below.

<?php
$curdir = basename(dirname(__FILE__));
require_once '../template/index.php';
?>

But the problem is when I create the file index.php, it writes as follows.

<?php
 = basename(dirname(__FILE__));
require_once '../template/index.php';
?>

the variable gets eliminated.

Please help me solve this problem.

    use single quotes.

    Single quotes will prevent PHP from parsing strings within the quotes.

    Try this example to see what I mean:

    <?php
    $var = 'a random var';
    
    echo "this is the var in double quotes: $var <br>";
    echo 'and this is the var in single quotes: $var <br>';
    

    Notice how the 2nd sentence will not parse the $var.

      Hi Desdinova,
      I have tried ur solution, but nothing happened.
      I m getting the same results.

        ganesh_dabhade;10973935 wrote:

        But the problem is when I create the file index.php, it writes as follows.

        how are you doing the creation?

          Thanks Desdinova and dagon for replying

          Desdinova , I got the direction from ur example

          I have changed my code to

          $line = '<?php 
          $curdir = basename(dirname(__FILE__));
          require_once \'../template/index.php\' ;
          ?>';

          and that's it. Done...

          dagon, I was using fwrite to create file.

          Thanks again..

            ganesh_dabhade;10973954 wrote:

            Thanks Desdinova and dagon for replying

            Desdinova , I got the direction from ur example

            I have changed my code to

            $line = '<?php 
            $curdir = basename(dirname(__FILE__));
            require_once \'../template/index.php\' ;
            ?>';

            and that's it. Done...

            dagon, I was using fwrite to create file.

            Thanks again..

            You can use the double quotes and try to escape variable, like this:

            $line = "<?php
            \$curdir = basename(dirname(__FILE__));
            require_once '../template/index.php' ;
            ?>";

              Wow, I can't edit post. Sorry, this:

              $line = "<?php
              \$curdir = basename(dirname(__FILE__));
              require_once '../template/index.php' ;
              ?>";
              
                Write a Reply...