473,395 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

write a content to file

118 100+
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. $handle = fopen("myfile.php", 'w+');
  4.  
  5. if($handle)
  6. {
  7. $text="<?php include('ClassName.class');$myclass = &new ClassName; echo $myclass->myfunction1(); ?>";
  8.     if(!fwrite($handle,$text))
  9.         die("couldn't write to file.");
  10.  
  11.     echo "success writing to file";
  12. }
  13.  
  14. ?>
  15.  
  16.  

errors : Notice: Undefined variable: myclass in F:\Facebook\furniture11\DataMining\public_html\adm in\files.php on line 6

Notice: Undefined variable: myclass in F:\Facebook\furniture11\DataMining\public_html\adm in\files.php on line 6
success writing to file
Aug 6 '08 #1
3 1268
Markus
6,050 Expert 4TB
Variables are parsed inside double quotes (")

So you will have to escape the variables with a backslash (\)
Aug 6 '08 #2
change the line:

Expand|Select|Wrap|Line Numbers
  1. $text="<?php include('ClassName.class');$myclass = &new ClassName; echo $myclass->myfunction1(); ?>";
  2.  
to this:

Expand|Select|Wrap|Line Numbers
  1. $text="<?php include('ClassName.class');\$myclass = &new ClassName; echo \$myclass->myfunction1(); ?>";
  2.  
Aug 6 '08 #3
Atli
5,058 Expert 4TB
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.
Aug 7 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: AC [MVP MCMS] | last post by:
Any pointers on how to (1) read a Base64 encoded string from a text file and (2) write it to a binary file? I have a ton of files that are being generated from a legacy system. Each file...
3
by: David Thielen | last post by:
Hi; I created a virtual directory in IIS 6.0 and my asp.net app runs fine. But when it tries to write a file I get: Access to the path is denied. - C:\Inetpub\wwwroot\RunReportASP\images ...
6
by: john.lum | last post by:
I am using document.write in an external javascript file to display some content, but I've found that I can't rely on that content being displayed in the location I expect. Here's a very simple...
3
by: broli85 | last post by:
I am writing an extension for Firefox 1.5. I would like to know if there is a way to write and read data to and from a file which is in the location of the extension (or somewhere in the user's...
16
by: btopenworld | last post by:
Hi - question from a relative asp novice I have written to text files in the past, but always appending new data to the end of the text file. I now want to add the new data to the beginning of...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
12
by: lalou89 | last post by:
Develop a simple text editor program. The program will show the user a menu of choices and will act according to his choice. Use functional decomposition to break the system into small functions that...
1
by: Curious | last post by:
I want to write to an output file, "C:\\temp\\debug.txt": If the file exists, append the new content to the end of the file (instead of overwriting the current content). If the file doesn't exist,...
4
by: AAaron123 | last post by:
trying to understand the below shown code. After this is run the browser opens a file-save dialog box for saving the file. I wonder how it knows I want the file saved? But more important, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.