Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-06-2008, 03:28 PM   PM User | #1
swethak
New Coder

 
Join Date: Jul 2008
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
swethak is an unknown quantity at this point
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

PHP 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\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
swethak is offline   Reply With Quote
Old 08-06-2008, 03:34 PM   PM User | #2
derzok
Regular Coder

 
Join Date: May 2008
Location: Ohio
Posts: 231
Thanks: 3
Thanked 21 Times in 21 Posts
derzok is an unknown quantity at this point
This is when a syntax highlighting editor comes in handy - vim shows me this:

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:



PHP 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";
}
?>
__________________
zok@zoklet:~$ whereis zok
zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

Last edited by derzok; 08-06-2008 at 03:38 PM..
derzok is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:03 AM.


Advertisement
Log in to turn off these ads.