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

Read and Write file contents

pradeepjain
563 512MB
Hii this is pradeep here . i am a newbie to PHP .can u help me out.
i hve a file called con.conf(configuration file) tht contains
name:pradeep
place:bangalore

i need to read this file and display the contents in form type in browser . and then gve a submit button so as to edit and update the file .
can u gve me a code for this process.
email:[ REMOVED ]
Jul 29 '07
59 4109
pradeepjain
563 512MB
Glad we finally got there on that.

As for writing back to the file the $_POST variable is really an array, so you can loop through the array and then write to file when you hit a key() value of name or location. This should sort you out nicely.

Have a go and if you get stuck post the code you've got and I'll have a play around with it.

Cheers
nathj

i did not get ur point...i can use $POST but whts the variable name to use ....bcos while reading i am using only str[0] for variable name. ..i need to use implode function rite!!...
Aug 4 '07 #51
pradeepjain
563 512MB
Glad we finally got there on that.

As for writing back to the file the $_POST variable is really an array, so you can loop through the array and then write to file when you hit a key() value of name or location. This should sort you out nicely.

Have a go and if you get stuck post the code you've got and I'll have a play around with it.

Cheers
nathj

u explian me how to do it...and i hve tht of this also...i wll use a count variable while reading and use name [count]=$str[0] and value[count] =$str[1] insie the while loop and as soon as we enter keep incrimenting count..
so tht its jst matter of for loop and implode in write function...
Aug 4 '07 #52
nathj
938 Expert 512MB
u explian me how to do it...and i hve tht of this also...i wll use a count variable while reading and use name [count]=$str[0] and value[count] =$str[1] insie the while loop and as soon as we enter keep incrimenting count..
so tht its jst matter of for loop and implode in write function...
The $_POST[] is really an associative array so yo ucan simply loop through it and for any thing where the key() is either name or location you can write an appropriate line to te text file.

Try something like:
[php]
foreach($_POST as $lcItem)
{
if (key() == 'name')
{
// write a line to the file using file functions
}
if (key() == 'location'
{
// write a line to the file using file functions
}
}
[/php]


I have not tried this, I am typing this whilst I play with my 9month old daughter - so that's me done for the weekend, I'll check back on monday.

Cheers
nathj
Aug 4 '07 #53
pradeepjain
563 512MB
The $_POST[] is really an associative array so yo ucan simply loop through it and for any thing where the key() is either name or location you can write an appropriate line to te text file.

Try something like:
[php]
foreach($_POST as $lcItem)
{
if (key() == 'name')
{
// write a line to the file using file functions
}
if (key() == 'location'
{
// write a line to the file using file functions
}
}
[/php]


I have not tried this, I am typing this whilst I play with my 9month old daughter - so that's me done for the weekend, I'll check back on monday.

Cheers
nathj

wht u hve said is 100% correct ..but i cannot hard code it ....bcos i wll be not knowing wht is in the file i wll be jst knowing tht there is a file and there are 2 strings seperated by ":" .....so i wll be not knowing tht it has name ,place or something else...so i cannot use if (key() == 'name')........i hve to dynamically read the names and write the content!!!!
Aug 4 '07 #54
nathj
938 Expert 512MB
wht u hve said is 100% correct ..but i cannot hard code it ....bcos i wll be not knowing wht is in the file i wll be jst knowing tht there is a file and there are 2 strings seperated by ":" .....so i wll be not knowing tht it has name ,place or something else...so i cannot use if (key() == 'name')........i hve to dynamically read the names and write the content!!!!
Well in that case, the key() function can still be of use to you. You write to the file key(): $_POST[key()]. This should do the trick.

Cheers
nathj
Aug 6 '07 #55
pradeepjain
563 512MB
guys thanks to all u who hve helped me....i finished my work
Aug 8 '07 #56
nathj
938 Expert 512MB
guys thanks to all u who hve helped me....i finished my work
I'm gald you got it working. Anytime you get stuck post back here - with your code and and your question.


Cheers
nathj
Aug 8 '07 #57
pradeepjain
563 512MB
hii this is a new problem

I need to read a folder and then take the images from there and display it in such a way tht after a certain time the neaxt image has to be taken ..in the sense it has to rotate all the images...any basic idea to do it..

thanks
pradeep
Aug 8 '07 #58
nathj
938 Expert 512MB
hii this is a new problem

I need to read a folder and then take the images from there and display it in such a way tht after a certain time the neaxt image has to be taken ..in the sense it has to rotate all the images...any basic idea to do it..

thanks
pradeep
Based on this scant outline I would suggest that you need to investigate the directory functions in PHP. This would enable you to create an array of images. You could loop through this array using some sort of timer (note this example would need to be adapted to control when code is executed inside a loop).

I have never done anything like this, but this is how I would approach the problem.

My recommendation is to have a go with this, or any other bsae line idea. If you get stuck I would post your code and your problem to a new thread. This one has a lot of posts on it now and people may be put off by that so you could miss out on some better help.

Cheers
nathj
Aug 8 '07 #59
pradeepjain
563 512MB
Based on this scant outline I would suggest that you need to investigate the directory functions in PHP. This would enable you to create an array of images. You could loop through this array using some sort of timer (note this example would need to be adapted to control when code is executed inside a loop).

I have never done anything like this, but this is how I would approach the problem.

My recommendation is to have a go with this, or any other bsae line idea. If you get stuck I would post your code and your problem to a new thread. This one has a lot of posts on it now and people may be put off by that so you could miss out on some better help.

Cheers
nathj







hiii i needed a small help on this plzz help
help on this
Nov 29 '07 #60

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

Similar topics

4
by: JDJones | last post by:
I'm trying to write a script that will read from a text list of songs that I burned onto my CD (Albums011.txt), then write to the database text the new text made ready for inserting into a...
2
by: Amy G | last post by:
I am looking to make this code a little "nicer"... any suggestions??? I want to do a "read+" where I would be able to first read the contents of the file... then either close the file out or write...
0
by: Joan Bos | last post by:
Hi, Is there somewhere on the Internet a description of what a .NET application config file should contain? For our application, I have to write passwords encrypted in a config file. The...
22
by: Jason Heyes | last post by:
Does this function need to call eof after the while-loop to be correct? bool read_file(std::string name, std::string &s) { std::ifstream in(name.c_str()); if (!in.is_open()) return false; ...
1
by: cnu | last post by:
My program generates a log file for every event that happens in the program. So, I open the file and keep it open till the end. This is how I open the file for writing: <CODE> public...
4
by: ESPN Lover | last post by:
Below is two snippets of code from MSDN showing how to read a file. Is one way preferred over the other and why? Thanks. using System; using System.IO; class Test { public static void...
10
by: Tibby | last post by:
I need to read/write not only text files, but binary as well. It seems like on binary files, it doesn't right the last 10% of the file. -- Thanks --- Outgoing mail is certified Virus...
8
by: kepioo | last post by:
I currently have an xml input file containing lots of data. My objectiv is to write a script that reports in another xml file only the data I am interested in. Doing this is really easy using SAX....
3
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
I try to follow Steve's paper to build a database, and store a small text file into SQL Server database and retrieve it later. Only difference between my table and Steve's table is that I use NTEXT...
2
by: Kevin Ar18 | last post by:
I posted this on the forum, but nobody seems to know the solution: http://python-forum.org/py/viewtopic.php?t=5230 I have a zip file that is several GB in size, and one of the files inside of it...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.