write a content to file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swethak
    New Member
    • May 2008
    • 118

    write a content to file

    hi

    i want to write a content in $text into the file. For that i wrote the below code .But i run that code i got the following errors.How i avoid that errors and write the whole content in $text into the file.plz help me

    Code:
    <?php
    $handle = fopen("myfile.php", 'w+');
    
    if($handle)
    {
    $text="<?php include('ClassName.class');$myclass = &new ClassName; echo $myclass->myfunction1(); ?>";
    	if(!fwrite($handle,$text))
    		die("couldn't write to file.");
    
    	echo "success writing to file";
    }
    
    ?>

    errors : Notice: Undefined variable: myclass in F:\Facebook\fur niture11\DataMi ning\public_htm l\admin\files.p hp on line 6

    Notice: Undefined variable: myclass in F:\Facebook\fur niture11\DataMi ning\public_htm l\admin\files.p hp on line 6
    success writing to file
    Last edited by swethak; Aug 6 '08, 02:26 PM. Reason: adding content
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Variables are parsed inside double quotes (")

    So you will have to escape the variables with a backslash (\)

    Comment

    • nashruddin
      New Member
      • Jun 2008
      • 25

      #3
      change the line:

      Code:
      $text="<?php include('ClassName.class');$myclass = &new ClassName; echo $myclass->myfunction1(); ?>";
      to this:

      Code:
      $text="<?php include('ClassName.class');\$myclass = &new ClassName; echo \$myclass->myfunction1(); ?>";

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Or, you could simply use single-quotes. Variables will not be parsed inside a single-quoted string.
        Just make sure you don't use any single-quotes inside the single-quoted string... obviously.

        Comment

        Working...