Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17358

Re: Storing a number inside a file

From "J.O. Aho" <user@example.net>
Newsgroups comp.lang.php
Subject Re: Storing a number inside a file
Date 2017-04-18 06:54 +0200
Message-ID <ellkgbFeqngU1@mid.individual.net> (permalink)
References <acaf6429-3976-44a5-9331-2339742028a1@googlegroups.com>

Show all headers | View raw


On 04/18/17 05:58, bit-naughty@hotmail.com wrote:
> I want to store a number, like "23" inside a file. The number will be the only thing in the file,
> and it will be incremented whenever I want it to. However - the length of the number can be anything,
> eg. 429 or 1985409...or whatever - ie. it's *length* can be anything. How do I do this?

Here is a simple example: https://www.w3schools.com/PHP/php_file_create.asp

Error handling not the perfect one, but you will be able to improve.



> And of course, how do I read the number inside the file when I want?

To read the data in the file to a string you can use file_get_contents,
see http://www.php.net/manual/en/function.file-get-contents.php

And then convert it to an integer, use intval, see
http://php.net/manual/en/function.intval.php


-- 

 //Aho

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Storing a number inside a file bit-naughty@hotmail.com - 2017-04-17 20:58 -0700
  Re: Storing a number inside a file "J.O. Aho" <user@example.net> - 2017-04-18 06:54 +0200
    Re: Storing a number inside a file Mi Na <ya12983@mail.com> - 2021-07-23 00:52 -0700

csiph-web