...

View Full Version : write a content to file



swethak
08-06-2008, 03:28 PM
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



<?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\furniture11\DataMining\public_html\admin\files.php on line 6

Notice: Undefined variable: myclass in F:\Facebook\furniture11\DataMining\public_html\admin\files.php on line 6
success writing to file

derzok
08-06-2008, 03:34 PM
This is when a syntax highlighting editor comes in handy - vim shows me this: http://zoklet.net/~zok/pics/vim.jpg

See the problem? You need to either escape your special characters (like $ and ->) or you need to use a different kind of quote (single quotes). Try this:

http://zoklet.net/~zok/pics/vim2.jpg



<?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";
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum