473,322 Members | 1,314 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,322 software developers and data experts.

Problem using fwrite function, passing a variable as parameter

196 100+
Ok basically i need to figure out why i cant pass a variable as a parmater in the fwrite function.

heres the code that does NOT work -

Expand|Select|Wrap|Line Numbers
  1. $output = "hello world"; //note not the actual string
  2. $file = fopen("test.xml", "w") or exit("Unable to open file!");
  3. fwrite($file, $output);
  4. fclose($file);
  5.  

and heres a variation that DOES work -

Expand|Select|Wrap|Line Numbers
  1. $file = fopen("test.xml", "w") or exit("Unable to open file!");
  2. fwrite($file, "hello world");
  3. fclose($file);
  4.  

For some reason it does not want to let me pass variable in the place of "hello world". I cant seem to identify any reason for this.


Any Help would be greatly appreciated, Thanks
Oct 24 '09 #1
7 2972
Dormilich
8,658 Expert Mod 8TB
there seems to be something wrong with the actual string to write. did you try with that simplified string?
Oct 24 '09 #2
chazzy69
196 100+
Yes i tried setting the variable = "hello world" which still produced the same problem.
Oct 24 '09 #3
Dormilich
8,658 Expert Mod 8TB
is it the same with an arbitraty text file (not .xml)?
Oct 24 '09 #4
chazzy69
196 100+
Yes i have even tried renaming the file to a .txt rather then .xml it makes no difference what so ever. Is it possible that specific function will not allow you to pass a variable or could it perhaps be a problem with say the current php version?
Oct 25 '09 #5
Markus
6,050 Expert 4TB
It works fine for me, Chazzy69. What PHP version are you using?
Oct 25 '09 #6
chazzy69
196 100+
Using PHP version 5.2.9,
Oct 26 '09 #7
chazzy69
196 100+
Ok gone back and done a little fiddling around if i set the variable to say anything it will work now but it doesn't seem to like the string that i want to pass for some reason. I mean all im making is an XML document with <tags>.

So not sure how to identify what is contained within the string that screwing it up or fix it. Any ideas?


Update: Ok seems that my original input has decided to go and screw up for some reason i.e. the string is blank when i try to write it to the file, lol. Thanks for the help pplz.
Oct 26 '09 #8

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

Similar topics

0
by: Eduardo Biano | last post by:
Hi, I am new to python and tried to pass parameters between one function to another. I tried two approaches in doing this but failed. The first is, I tried to assign a variable in foo1()...
4
by: sam1967 | last post by:
How do I get a function to return a GMP integer type mpz_t when i try it i get an error message. i am trying mpz_t hooch (int x) { mpz_t y; ........
14
by: Mike Labosh | last post by:
How do you define whether the return value of a function is ByRef or ByVal? I have a utility class that cleans imported records by doing *really heavy* string manipulation in lots of different...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
9
by: burningsunorama | last post by:
Hi guys! This is maybe a too 'academic problem', but I would like to hear your opinions, something like pros and cons for each approach.... ... Recently we've had at work a little talk about the...
6
by: semkaa | last post by:
Can you explain why using ref keyword for passing parameters works slower that passing parameters by values itself. I wrote 2 examples to test it: //using ref static void Main(string args) {...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
65
by: Arjen | last post by:
Hi, Form a performance perspective, is it wise to use the ref statement as much as possible? Thanks! Arjen
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.