473,775 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read and Write file contents

pradeepjain
563 Contributor
Hii this is pradeep here . i am a newbie to PHP .can u help me out.
i hve a file called con.conf(config uration 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 4175
pradeepjain
563 Contributor
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 Contributor
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 Recognized Expert Contributor
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 Contributor
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 Recognized Expert Contributor
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 Contributor
guys thanks to all u who hve helped me....i finished my work
Aug 8 '07 #56
nathj
938 Recognized Expert Contributor
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 Contributor
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 Recognized Expert Contributor
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 Contributor
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
2930
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 database. The entries from the Albums011.txt look like this: Wayne Newton - Wild Cool & Swingin' - 03 - But Not For Me.mp3 Wayne Newton - Wild Cool & Swingin' - 04 - Wives And Lovers.mp3 etc. and I want to manipulate it them to look in the...
2
2785
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 to the file without appending. I want to overwrite the content. vacation_message = "blah blah blah" f_vm=open("/home/%s/.vacation.msg" %userid, 'r') lines=f_vm.readlines() f_vm.close()
0
1391
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 Enterprise Library does have an encryption method, but that method doesn't just return a value - no - it wants to write the value immediately to a config file. Except, it always gives an error, because no config file contents are ever good enough for...
22
13333
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; char c; std::string str;
1
6768
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 CLogHandler() { this.m_fsLog = new FileStream(strTodaysLogFile, System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.Read); this.m_swLog = new StreamWriter(this.m_fsLog);
4
2748
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 Main()
10
2545
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 Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003
8
1887
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. The input file is continuously updated. However, the other xml file should be updated only on request. Everytime we run the script, we track the new elements in the input file and report them in the output file.
3
2961
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 datatype for the file instead of using IMAGE datatype. I can not use SqlDataReader to read the data. I need your help, Thanks. -David (1) I have a table TestFile for testing: ID int FileName navrchar(255)
2
5454
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 is several GB in size. When it comes time to read the 5+GB file from inside the zip file, it fails with the following error: File "...\zipfile.py", line 491, in read bytes = self.fp.read(zinfo.compress_size) OverflowError: long it too large to...
0
9622
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10109
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10051
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9916
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5360
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.