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

(newbie) altering variables in external files

Sorry to take up your precious time with such a trivial matter, but could someone let me know how to (if it's possible) increment a variable in a text file.

Say if visitors.txt had "visitors=23" in it, how would I increment this from a php script? The only solution to this as far as I can see with my 5 days of php experience would be to re-write the file using fopen(). It seems to me there should be an easier way.

Many thanks to anyone who replies.
Aug 26 '05 #1
3 1355
have you tried using $visitors++
Jul 28 '07 #2
kovik
1,044 Expert 1GB
No, you'd need to overwrite it. You open the file, extract the variable from the text, increment that variable and insert it back into the contents, then overwrite the file with the new contents.

This is why we don't use files... We use databases.
Jul 28 '07 #3
pradeepjain
563 512MB
Sorry to take up your precious time with such a trivial matter, but could someone let me know how to (if it's possible) increment a variable in a text file.

Say if visitors.txt had "visitors=23" in it, how would I increment this from a php script? The only solution to this as far as I can see with my 5 days of php experience would be to re-write the file using fopen(). It seems to me there should be an easier way.

Many thanks to anyone who replies.


HII..
CAN U SEND ME UR CODE...BCOS I NEED A CODE SIMILAR TO URS ..WRITING TO THE FILE
Jul 30 '07 #4

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

Similar topics

2
by: SA | last post by:
hello, i have many pages (page1.php .. page100.php) and each of them include some fixed subpages (top.php, bottom.php). each subpage (top.php, bottom.php) uses a variable ("theme") defined in...
12
by: fox | last post by:
How do I (portably) make a forward reference to a static (I mean file-scope) variable? I've been using "extern" for years, for example: extern int x; int foo(void) { return x++; }
44
by: fabio | last post by:
Why? i' ve heard about this, the usage of global vars instead of locals is discouraged, but why? thx :)
28
by: John Salerno | last post by:
What is the best way of altering something (in my case, a file) while you are iterating over it? I've tried this before by accident and got an error, naturally. I'm trying to read the lines of a...
1
by: metiu | last post by:
Hi all, maybe it's an old question, but I couldn't find an answer... let's say I have this kind of directory structure for project foo: /foo/includes/mod1.h (exported by mod1)...
9
by: JimmyKoolPantz | last post by:
IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. ...
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
10
by: Mladen Gogala | last post by:
I am a Python newbie who decided to see what that Python fuss is all about. Quite frankly, I am a bit perplexed. After having had few months of experience with Perl (started in 1994 with Perl v4,...
11
by: sinbad | last post by:
hi, I've a very large C program consisting of hundred of files; I want to know what are all the global variables defined in the program. how do i do this. thanks
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

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.