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


Groups > comp.lang.php > #11817 > unrolled thread

Perform maths based on a number in a text file

Started bydrkirkby@gmail.com
First post2013-11-18 01:23 -0800
Last post2013-11-21 03:10 +0000
Articles 16 — 8 participants

Back to article view | Back to comp.lang.php


Contents

  Perform maths based on a number in a text file drkirkby@gmail.com - 2013-11-18 01:23 -0800
    Re: Perform maths based on a number in a text file Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-18 11:57 +0100
    Re: Perform maths based on a number in a text file The Natural Philosopher <tnp@invalid.invalid> - 2013-11-18 13:19 +0000
      Re: Perform maths based on a number in a text file Tim Streater <timstreater@greenbee.net> - 2013-11-18 15:08 +0000
        Re: Perform maths based on a number in a text file The Natural Philosopher <tnp@invalid.invalid> - 2013-11-18 16:22 +0000
          Re: Perform maths based on a number in a text file Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-18 16:50 +0000
          Re: Perform maths based on a number in a text file Tim Streater <timstreater@greenbee.net> - 2013-11-18 16:53 +0000
      Re: Perform maths based on a number in a text file drkirkby@gmail.com - 2013-11-20 03:50 -0800
        Re: Perform maths based on a number in a text file David Robley <me@home.invalid> - 2013-11-20 22:32 +1030
        Re: Perform maths based on a number in a text file The Natural Philosopher <tnp@invalid.invalid> - 2013-11-20 13:03 +0000
        Re: Perform maths based on a number in a text file Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-20 11:20 -0500
    Re: Perform maths based on a number in a text file Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-18 14:46 +0000
      Re: Perform maths based on a number in a text file drkirkby@gmail.com - 2013-11-20 03:53 -0800
    Re: Perform maths based on a number in a text file Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-18 11:38 -0500
      Re: Perform maths based on a number in a text file drkirkby@gmail.com - 2013-11-20 03:58 -0800
    Re: Perform maths based on a number in a text file Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-21 03:10 +0000

#11817 — Perform maths based on a number in a text file

Fromdrkirkby@gmail.com
Date2013-11-18 01:23 -0800
SubjectPerform maths based on a number in a text file
Message-ID<83ddeb0e-5749-4602-bda0-e9d6770feb44@googlegroups.com>
I'm tyring to simplify the design of a web site which uses PHP, and hope someone can help me.  Basically I want to store a number in a file on a web site, and display that number, or a variation of it, on a number of web pages. Let's say the parameter is "A", and is 10 ps. Three different web pages need to display this number, but in 3 different ways. 

1) First page shows just A
2) Second page multiples A by 3
3) Third page multiples A by -2

So if A was 10

1) Page 1 should show 10
2) Page 2 should show 30
3) Page 3 should show -20. 

If the value of A changes, I'd like to update the web site in one place, and not go around to every page updating them individually, as that will be error prone. 

Is there a way to put the value of A in a text file, and use the value in different parts of the site? If so how? 

Since there will actually be 15 or so parameters, A, B, C ..., is there a way I can put all 15 parameters in a file (perhaps one per line, or with white space between them), rather than have 15 different files? 

If you look at this web page which is for an economimcal / low cost vector network analyzer kit, 

http://www.vnacalibration.co.uk/support/85033/Rohde+Schwarz/

you can see the numeric values in the form used by Rohde & Schwarz for their vector network analyzers, whereas in this page which is a bit longer, under the section "Standard Definitions", 

http://www.vnacalibration.co.uk/support/85033/HP/

one has basicaly the same parameters, but expressed in a different way. Another make of vector network analyzer wants the parameters in a different way. 

Any thoughts? 

Dave 

[toc] | [next] | [standalone]


#11818

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-11-18 11:57 +0100
Message-ID<20674060.4IAKZ2NE0I@PointedEars.de>
In reply to#11817
drkirkby@gmail.com wrote:

> […]
> So if A was 10
> 
> 1) Page 1 should show 10
> 2) Page 2 should show 30
> 3) Page 3 should show -20.
> 
> If the value of A changes, I'd like to update the web site in one place,
> and not go around to every page updating them individually, as that will
> be error prone.
> 
> Is there a way to put the value of A in a text file, and use the value in
> different parts of the site? If so how?

<http://php.net/file_put_contents>
<http://php.net/file_get_contents>

However, it would be easier to include a constant definition.
 
> Since there will actually be 15 or so parameters, A, B, C ..., is there a
> way I can put all 15 parameters in a file (perhaps one per line, or with
> white space between them), rather than have 15 different files?

Yes.
 
> Any thoughts?

Do your own homework.

-- 
When all you know is jQuery, every problem looks $(olvable).

[toc] | [prev] | [next] | [standalone]


#11820

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2013-11-18 13:19 +0000
Message-ID<l6d45m$67d$1@news.albasani.net>
In reply to#11817
On 18/11/13 09:23, drkirkby@gmail.com wrote:
> I'm tyring to simplify the design of a web site which uses PHP, and
> hope someone can help me.  Basically I want to store a number in a
> file on a web site, and display that number, or a variation of it, on
> a number of web pages. Let's say the parameter is "A", and is 10 ps.
> Three different web pages need to display this number, but in 3
> different ways.
>
> 1) First page shows just A 2) Second page multiples A by 3 3) Third
> page multiples A by -2
>
> So if A was 10
>
> 1) Page 1 should show 10 2) Page 2 should show 30 3) Page 3 should
> show -20.
>
> If the value of A changes, I'd like to update the web site in one
> place, and not go around to every page updating them individually, as
> that will be error prone.
>
> Is there a way to put the value of A in a text file, and use the
> value in different parts of the site? If so how?
>

yes.

> Since there will actually be 15 or so parameters, A, B, C ..., is
> there a way I can put all 15 parameters in a file (perhaps one per
> line, or with white space between them), rather than have 15
> different files?
>

yes. Or a database table. Rather than a file.

> If you look at this web page which is for an economimcal / low cost
> vector network analyzer kit,
>
> http://www.vnacalibration.co.uk/support/85033/Rohde+Schwarz/
>
> you can see the numeric values in the form used by Rohde & Schwarz
> for their vector network analyzers, whereas in this page which is a
> bit longer, under the section "Standard Definitions",
>
> http://www.vnacalibration.co.uk/support/85033/HP/
>
> one has basicaly the same parameters, but expressed in a different
> way. Another make of vector network analyzer wants the parameters in
> a different way.
>
> Any thoughts?
>
This is not a big problem intrinsically, but the implementation detail 
is where the work would be.

I would strongly recommend using a database: setting that up is a bit of 
a faff, but once set up it provides the sort of 'update by one screen, 
read buy many others' sort of access that you need. And wont need any 
file level parsing - you will get your numbers as an array from a Mysql 
type query.

  You can even embed the mathematics in the query instead of doing it on 
PHP, if you want.

But all this assumes you are willing to knuckle down and learn basic 
SQL, mysql administration, and how to set up web forms and the like.

If you are as you sound, a relative newcomer, this is a few weeks work :-(

However it's an ideal problem to cut your teeth on. :-)



> Dave
>


-- 
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.

[toc] | [prev] | [next] | [standalone]


#11827

FromTim Streater <timstreater@greenbee.net>
Date2013-11-18 15:08 +0000
Message-ID<181120131508210843%timstreater@greenbee.net>
In reply to#11820
In article <l6d45m$67d$1@news.albasani.net>, The Natural Philosopher
<tnp@invalid.invalid> wrote:

> On 18/11/13 09:23, drkirkby@gmail.com wrote:
> > I'm tyring to simplify the design of a web site which uses PHP, and
> > hope someone can help me.  Basically I want to store a number in a
> > file on a web site, and display that number, or a variation of it, on
> > a number of web pages. Let's say the parameter is "A", and is 10 ps.
> > Three different web pages need to display this number, but in 3
> > different ways.
> >
> > 1) First page shows just A 2) Second page multiples A by 3 3) Third
> > page multiples A by -2
> >
> > So if A was 10
> >
> > 1) Page 1 should show 10 2) Page 2 should show 30 3) Page 3 should
> > show -20.
> >
> > If the value of A changes, I'd like to update the web site in one
> > place, and not go around to every page updating them individually, as
> > that will be error prone.
> >
> > Is there a way to put the value of A in a text file, and use the
> > value in different parts of the site? If so how?
> >
> 
> yes.
> 
> > Since there will actually be 15 or so parameters, A, B, C ..., is
> > there a way I can put all 15 parameters in a file (perhaps one per
> > line, or with white space between them), rather than have 15
> > different files?
> >
> 
> yes. Or a database table. Rather than a file.
> 
> > If you look at this web page which is for an economimcal / low cost
> > vector network analyzer kit,
> >
> > http://www.vnacalibration.co.uk/support/85033/Rohde+Schwarz/
> >
> > you can see the numeric values in the form used by Rohde & Schwarz
> > for their vector network analyzers, whereas in this page which is a
> > bit longer, under the section "Standard Definitions",
> >
> > http://www.vnacalibration.co.uk/support/85033/HP/
> >
> > one has basicaly the same parameters, but expressed in a different
> > way. Another make of vector network analyzer wants the parameters in
> > a different way.
> >
> > Any thoughts?
> >
> This is not a big problem intrinsically, but the implementation detail 
> is where the work would be.
> 
> I would strongly recommend using a database: setting that up is a bit of 
> a faff, but once set up it provides the sort of 'update by one screen, 
> read buy many others' sort of access that you need. And wont need any 
> file level parsing - you will get your numbers as an array from a Mysql 
> type query.

Why even bother with mysql. Use SQLite, where administration is zero.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#11834

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2013-11-18 16:22 +0000
Message-ID<l6desn$s68$1@news.albasani.net>
In reply to#11827
On 18/11/13 15:08, Tim Streater wrote:
> In article <l6d45m$67d$1@news.albasani.net>, The Natural Philosopher
> <tnp@invalid.invalid> wrote:
>
>> On 18/11/13 09:23, drkirkby@gmail.com wrote:
>> > I'm tyring to simplify the design of a web site which uses PHP, and
>> > hope someone can help me.  Basically I want to store a number in a
>> > file on a web site, and display that number, or a variation of it, on
>> > a number of web pages. Let's say the parameter is "A", and is 10 ps.
>> > Three different web pages need to display this number, but in 3
>> > different ways.
>> >
>> > 1) First page shows just A 2) Second page multiples A by 3 3) Third
>> > page multiples A by -2
>> >
>> > So if A was 10
>> >
>> > 1) Page 1 should show 10 2) Page 2 should show 30 3) Page 3 should
>> > show -20.
>> >
>> > If the value of A changes, I'd like to update the web site in one
>> > place, and not go around to every page updating them individually, as
>> > that will be error prone.
>> >
>> > Is there a way to put the value of A in a text file, and use the
>> > value in different parts of the site? If so how?
>> >
>>
>> yes.
>>
>> > Since there will actually be 15 or so parameters, A, B, C ..., is
>> > there a way I can put all 15 parameters in a file (perhaps one per
>> > line, or with white space between them), rather than have 15
>> > different files?
>> >
>>
>> yes. Or a database table. Rather than a file.
>>
>> > If you look at this web page which is for an economimcal / low cost
>> > vector network analyzer kit,
>> >
>> > http://www.vnacalibration.co.uk/support/85033/Rohde+Schwarz/
>> >
>> > you can see the numeric values in the form used by Rohde & Schwarz
>> > for their vector network analyzers, whereas in this page which is a
>> > bit longer, under the section "Standard Definitions",
>> >
>> > http://www.vnacalibration.co.uk/support/85033/HP/
>> >
>> > one has basicaly the same parameters, but expressed in a different
>> > way. Another make of vector network analyzer wants the parameters in
>> > a different way.
>> >
>> > Any thoughts?
>> >
>> This is not a big problem intrinsically, but the implementation detail
>> is where the work would be.
>>
>> I would strongly recommend using a database: setting that up is a bit
>> of a faff, but once set up it provides the sort of 'update by one
>> screen, read buy many others' sort of access that you need. And wont
>> need any file level parsing - you will get your numbers as an array
>> from a Mysql type query.
>
> Why even bother with mysql. Use SQLite, where administration is zero.
>

Well I would have suggested it if I had ever used it myself, which I 
haven't.

I wasn't aware it did file locking and so on and had a proper 'daemon'

-- 
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to 
lead are elected by the least capable of producing, and where the 
members of society least likely to sustain themselves or succeed, are 
rewarded with goods and services paid for by the confiscated wealth of a 
diminishing number of producers.

[toc] | [prev] | [next] | [standalone]


#11838

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-11-18 16:50 +0000
Message-ID<0.efd6fed2a4933a14406b.20131118165004GMT.87siutpscj.fsf@bsb.me.uk>
In reply to#11834
The Natural Philosopher <tnp@invalid.invalid> writes:

> On 18/11/13 15:08, Tim Streater wrote:
<snip>
>> Why even bother with mysql. Use SQLite, where administration is zero.
>>
>
> Well I would have suggested it if I had ever used it myself, which I
> haven't.
>
> I wasn't aware it did file locking and so on and had a proper 'daemon'

It has locking and proper transactions (sqlite3 is better than sqlite2
in this regard) but no remote access.

When that is not required, it's an advantage rather than a disadvantage
in that there is one less thing to fail, one less service to manage, one
less login to remember and/or protect, and so on.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#11839

FromTim Streater <timstreater@greenbee.net>
Date2013-11-18 16:53 +0000
Message-ID<181120131653581069%timstreater@greenbee.net>
In reply to#11834
In article <l6desn$s68$1@news.albasani.net>, The Natural Philosopher
<tnp@invalid.invalid> wrote:

> On 18/11/13 15:08, Tim Streater wrote:

> > Why even bother with mysql. Use SQLite, where administration is zero.
> 
> Well I would have suggested it if I had ever used it myself, which I 
> haven't.
> 
> I wasn't aware it did file locking and so on and had a proper 'daemon'

It's not server-based, it's a useful replacement for fopen (). See:

<http://www.sqlite.org/whentouse.html>

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#11874

Fromdrkirkby@gmail.com
Date2013-11-20 03:50 -0800
Message-ID<138d7da0-4c11-4efe-befb-9e40bbef9f9c@googlegroups.com>
In reply to#11820
On Monday, 18 November 2013 13:19:50 UTC, The Natural Philosopher  wrote:
 
> I would strongly recommend using a database: setting that up is a bit of 
> 
> a faff, but once set up it provides the sort of 'update by one screen, 
> 
> read buy many others' sort of access that you need. And wont need any 
> 
> file level parsing - you will get your numbers as an array from a Mysql 
> 
> type query.
> 
> 
> 
>   You can even embed the mathematics in the query instead of doing it on 
> 
> PHP, if you want.
> 
> 
> 
> But all this assumes you are willing to knuckle down and learn basic 
> 
> SQL, mysql administration, and how to set up web forms and the like.
> 
> 
> 
> If you are as you sound, a relative newcomer, this is a few weeks work :-(

Hi, 
thank you for your thoughs. To be honest, I'm not over keen on using a database. I'm not a web designer, but an engineer trying to get data about his product on a web page. Maybe the constants will be updated in the future, but perhaps they never will. It is certainly not something I expect to do on a regular basis. The idea of spending 3 days working on this does not attract me. 

To answer the question asked by someone else about how the constants will get updated. It will be me doing it manually - no program will update them. Maybe file_get_contents will do what I want. 

Dave 

[toc] | [prev] | [next] | [standalone]


#11877

FromDavid Robley <me@home.invalid>
Date2013-11-20 22:32 +1030
Message-ID<l6i88p$sgu$1@news.albasani.net>
In reply to#11874
drkirkby@gmail.com wrote:

> On Monday, 18 November 2013 13:19:50 UTC, The Natural Philosopher  wrote:
>  
>> I would strongly recommend using a database: setting that up is a bit of
>> a faff, but once set up it provides the sort of 'update by one screen,
>> read buy many others' sort of access that you need. And wont need any
>> file level parsing - you will get your numbers as an array from a Mysql
>> type query.
>> 
>>   You can even embed the mathematics in the query instead of doing it on
>> PHP, if you want.
>> 
>> But all this assumes you are willing to knuckle down and learn basic
>> SQL, mysql administration, and how to set up web forms and the like.

>> 
>> If you are as you sound, a relative newcomer, this is a few weeks work
>> :-(
> 
> Hi,
> thank you for your thoughs. To be honest, I'm not over keen on using a
> database. I'm not a web designer, but an engineer trying to get data about
> his product on a web page. Maybe the constants will be updated in the
> future, but perhaps they never will. It is certainly not something I
> expect to do on a regular basis. The idea of spending 3 days working on
> this does not attract me.
> 
> To answer the question asked by someone else about how the constants will
> get updated. It will be me doing it manually - no program will update
> them. Maybe file_get_contents will do what I want.
> 
> Dave

Another possibility would be to add the values as variables in a file and 
then include() that file in scripts where the value(s) need to be used.

For example:

variables.inc
<?php
$thisvar = 3;
$thatvar = 7;
?>

And then in any script that needs to know these values something like:

<?php
//.....
include 'variables.inc';
$new_thisvar = $thisvar * 3;
//.....
?>

Add other ingredients to taste :-)

-- 
Cheers
David Robley

Useless Invention: Self stick frying pan.

[toc] | [prev] | [next] | [standalone]


#11878

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2013-11-20 13:03 +0000
Message-ID<l6ibvi$4d9$1@news.albasani.net>
In reply to#11874
On 20/11/13 11:50, drkirkby@gmail.com wrote:
> On Monday, 18 November 2013 13:19:50 UTC, The Natural Philosopher  wrote:
>
>> I would strongly recommend using a database: setting that up is a bit of
>>
>> a faff, but once set up it provides the sort of 'update by one screen,
>>
>> read buy many others' sort of access that you need. And wont need any
>>
>> file level parsing - you will get your numbers as an array from a Mysql
>>
>> type query.
>>
>>
>>
>>    You can even embed the mathematics in the query instead of doing it on
>>
>> PHP, if you want.
>>
>>
>>
>> But all this assumes you are willing to knuckle down and learn basic
>>
>> SQL, mysql administration, and how to set up web forms and the like.
>>
>>
>>
>> If you are as you sound, a relative newcomer, this is a few weeks work :-(
>
> Hi,
> thank you for your thoughs. To be honest, I'm not over keen on using a database. I'm not a web designer, but an engineer trying to get data about his product on a web page. Maybe the constants will be updated in the future, but perhaps they never will. It is certainly not something I expect to do on a regular basis. The idea of spending 3 days working on this does not attract me.
>
> To answer the question asked by someone else about how the constants will get updated. It will be me doing it manually - no program will update them. Maybe file_get_contents will do what I want.
>

It will, but instead of learning the database thingy, you need to learn 
the file parse thingy...


Now it so happens I do both, so this is a code fragment that loads a 
'one value per line' file of floating point numbers into PHP variables..

Its from this web page

http://www.gridwatch.templar.co.uk

and the results drive the dials there.

The file is itself generated by an asychronous process that scrapes data 
from elsewhere.

The data comes in as megawatts: I wanted floating point gigawatts hence 
the conversions.

------------------------
$retval=file_get_contents("/tmp/nationalgrid");
$results=explode("\n",$retval);
$demand=$results[12];
$freq=$results[13];
$nuclear=sprintf("%0.2f",$results[4]/1000);
$coal=sprintf("%0.2f",$results[3]/1000);
$ccgt=sprintf("%0.2f",$results[0]/1000);
$wind=sprintf("%0.2f",$results[5]/1000);
$hydro=sprintf("%0.2f",$results[7]/1000);
$pumped=sprintf("%0.2f",$results[6]/1000);
$french=sprintf("%0.2f",$results[9]/1000);
$irish=sprintf("%0.2f",$results[10]/1000);
$dutch=sprintf("%0.2f",$results[11]/1000);
$ew=sprintf("%0.2f",$results[14]/1000);
$oil=sprintf("%0.2f",$results[2]/1000);
$ocgt=sprintf("%0.2f",$results[1]/1000);
$other=sprintf("%0.2f",$results[8]/1000);

---------------------------------------

If you can organise your file like that then this is about as crude and 
simple as it gets.

This is a snapshot of the file

$cat /tmp/nationalgrid
13978
0
0
17061
7533
5303
281
451
614
48
-252
598
45944
50.133
0.000
-----------------------------------------


Note that PHP will dependent on context look at a string like "3.72" and 
interpret it as a string OR a floating point number, depending on the 
operation you are doing on it. Dividing or multiplying such a string 
forces it to be treated like a number. Printing it produces a string etc.

printf and sprintf are handy ways to format the number for display purposes.

explode is a handy way to split a string into an array of chunks 
delimited by another string - in this case the end of line charracter.

ensure that the file you create is readable by the web server you are using.


> Dave
>


-- 
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to 
lead are elected by the least capable of producing, and where the 
members of society least likely to sustain themselves or succeed, are 
rewarded with goods and services paid for by the confiscated wealth of a 
diminishing number of producers.

[toc] | [prev] | [next] | [standalone]


#11880

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-11-20 11:20 -0500
Message-ID<l6inh5$uq6$1@dont-email.me>
In reply to#11874
On 11/20/2013 6:50 AM, drkirkby@gmail.com wrote:
> On Monday, 18 November 2013 13:19:50 UTC, The Natural Philosopher  wrote:
>
>> I would strongly recommend using a database: setting that up is a bit of
>>
>> a faff, but once set up it provides the sort of 'update by one screen,
>>
>> read buy many others' sort of access that you need. And wont need any
>>
>> file level parsing - you will get your numbers as an array from a Mysql
>>
>> type query.
>>
>>
>>
>>    You can even embed the mathematics in the query instead of doing it on
>>
>> PHP, if you want.
>>
>>
>>
>> But all this assumes you are willing to knuckle down and learn basic
>>
>> SQL, mysql administration, and how to set up web forms and the like.
>>
>>
>>
>> If you are as you sound, a relative newcomer, this is a few weeks work :-(
>
> Hi,
> thank you for your thoughs. To be honest, I'm not over keen on using a database. I'm not a web designer, but an engineer trying to get data about his product on a web page. Maybe the constants will be updated in the future, but perhaps they never will. It is certainly not something I expect to do on a regular basis. The idea of spending 3 days working on this does not attract me.
>
> To answer the question asked by someone else about how the constants will get updated. It will be me doing it manually - no program will update them. Maybe file_get_contents will do what I want.
>
> Dave
>

If they're only going to be updated very rarely, and done so manually, I 
would just stick them in a .php file as defined constants, i.e.

# File constants.php
<?php
define ('CONST1', 42);
define ('CONST2', 53);
... etc.
?>

Then in the scripts where you need the constants, use:

# File script1.php

<?php
require_once('constants.php');

$value1 = CONST1 * 3; // 126
$value2 = CONST2 + 5; // 58

?>

The advantage of using constants is that a script cannot change them.

P.S. For personal preferences, I place all files like this outside of 
the websites DOCUMENT_ROOT directory and access them relative to 
DOCUMENT_ROOT.  For instance, if my DOCUMENT_ROOT directory is

/var/www/mysite/html

I would place it as

/var/www/mysite/constants.php

then access them everywhere with

require_once($_SERVER['DOCUMENT_ROOT'] . '/constants.php');

This has three advantages - it prevents the file from being accessed 
directly from the web (not a real concern in this case), it keeps 
included (only) scripts from cluttering up your directories with 
web-accessible files, and keeps the include code the same for any 
script, no matter where in your website directory.

The only real downside is you must update the file locally and upload it 
to the server or ssh into the server and edit the file there.  (You 
could build a web page to modify the script - but if it isn't going to 
be changed often, why bother?).

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#11824

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-11-18 14:46 +0000
Message-ID<0.761e54d7b542524684cc.20131118144604GMT.87y54lpy37.fsf@bsb.me.uk>
In reply to#11817
drkirkby@gmail.com writes:

> I'm tyring to simplify the design of a web site which uses PHP, and
> hope someone can help me.  Basically I want to store a number in a
> file on a web site, and display that number, or a variation of it, on
> a number of web pages. Let's say the parameter is "A", and is 10
> ps. Three different web pages need to display this number, but in 3
> different ways.
>
> 1) First page shows just A
> 2) Second page multiples A by 3
> 3) Third page multiples A by -2
<snip>
> Since there will actually be 15 or so parameters, A, B, C ..., is
> there a way I can put all 15 parameters in a file (perhaps one per
> line, or with white space between them), rather than have 15 different
> files?

There is a missing piece of information.  How will these numbers be
updated?  If they will change because you choose to alter them, then
just put them into a PHP source file that is included in each of the
pages.  They can be written as named constants or as an array indexed
in whatever way makes the accesses clearer.

If the updates are to be done by some page or other (by which I really
mean if the updates are done by some software on the server) then
putting them into a file will pay off.  Personally, 15 numbers is below
the threshold I have for setting up a database, but if I did choose a
database, I'd most likely use something very simple like sqlite.

For the programmed option you don't need much more than 'split' and
'file_get_contents' ('join' and 'file_put_contents' to save).

<snip>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#11875

Fromdrkirkby@gmail.com
Date2013-11-20 03:53 -0800
Message-ID<02b80e63-b5ce-4098-b6b7-914c2e75d306@googlegroups.com>
In reply to#11824
On Monday, 18 November 2013 14:46:04 UTC, Ben Bacarisse  wrote:
> drkirkby@gmail.com writes:
> 
> 
> 
> > I'm tyring to simplify the design of a web site which uses PHP, and
> 
> > hope someone can help me.  Basically I want to store a number in a
> 
> > file on a web site, and display that number, or a variation of it, on
> 
> > a number of web pages. Let's say the parameter is "A", and is 10
> 
> > ps. Three different web pages need to display this number, but in 3
> 
> > different ways.
> 
> >
> 
> > 1) First page shows just A
> 
> > 2) Second page multiples A by 3
> 
> > 3) Third page multiples A by -2
> 
> <snip>
> 
> > Since there will actually be 15 or so parameters, A, B, C ..., is
> 
> > there a way I can put all 15 parameters in a file (perhaps one per
> 
> > line, or with white space between them), rather than have 15 different
> 
> > files?
> 
> 
> 
> There is a missing piece of information.  How will these numbers be
> 
> updated?  If they will change because you choose to alter them, then
> 
> just put them into a PHP source file that is included in each of the
> 
> pages.  They can be written as named constants or as an array indexed
> 
> in whatever way makes the accesses clearer.

Thank you Ben.

The constants will be updated manually by me - not by any software. 

Dave 

[toc] | [prev] | [next] | [standalone]


#11837

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-11-18 11:38 -0500
Message-ID<l6dfq5$2gc$2@dont-email.me>
In reply to#11817
On 11/18/2013 4:23 AM, drkirkby@gmail.com wrote:
> I'm tyring to simplify the design of a web site which uses PHP, and hope someone can help me.  Basically I want to store a number in a file on a web site, and display that number, or a variation of it, on a number of web pages. Let's say the parameter is "A", and is 10 ps. Three different web pages need to display this number, but in 3 different ways.
>
> 1) First page shows just A
> 2) Second page multiples A by 3
> 3) Third page multiples A by -2
>
> So if A was 10
>
> 1) Page 1 should show 10
> 2) Page 2 should show 30
> 3) Page 3 should show -20.
>
> If the value of A changes, I'd like to update the web site in one place, and not go around to every page updating them individually, as that will be error prone.
>
> Is there a way to put the value of A in a text file, and use the value in different parts of the site? If so how?
>
> Since there will actually be 15 or so parameters, A, B, C ..., is there a way I can put all 15 parameters in a file (perhaps one per line, or with white space between them), rather than have 15 different files?
>
> If you look at this web page which is for an economimcal / low cost vector network analyzer kit,
>
> http://www.vnacalibration.co.uk/support/85033/Rohde+Schwarz/
>
> you can see the numeric values in the form used by Rohde & Schwarz for their vector network analyzers, whereas in this page which is a bit longer, under the section "Standard Definitions",
>
> http://www.vnacalibration.co.uk/support/85033/HP/
>
> one has basicaly the same parameters, but expressed in a different way. Another make of vector network analyzer wants the parameters in a different way.
>
> Any thoughts?
>
> Dave
>

Sure.  Look up the file functions - fopen, fread, fwrite, etc.  But you 
do have to watch out that another script is not accessing the file while 
you are writing it.  Additionally, when you do write the file, you will 
need to write all values unless you're changing the last one.

Easier would be a database which solves these problems for you.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#11876

Fromdrkirkby@gmail.com
Date2013-11-20 03:58 -0800
Message-ID<2fae8e13-6def-49cf-985d-114d42ea4acd@googlegroups.com>
In reply to#11837
On Monday, 18 November 2013 16:38:29 UTC, Jerry Stuckle  wrote:

> Sure.  Look up the file functions - fopen, fread, fwrite, etc.  But you 
> 
> do have to watch out that another script is not accessing the file while 
> 
> you are writing it.  Additionally, when you do write the file, you will 
> 
> need to write all values unless you're changing the last one.

I can edit the file with the constant in it using just a text editor (vi).  No script or any other automated software will do it. 

Since I know C, fopen, fread, fwrite probably have very similar meanings, and I could probably work that out. 

Dave 

[toc] | [prev] | [next] | [standalone]


#11881

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-11-21 03:10 +0000
Message-ID<l6jtj6$k1r$2@dont-email.me>
In reply to#11817
On Mon, 18 Nov 2013 01:23:06 -0800, drkirkby wrote:

> I'm tyring to simplify the design of a web site which uses PHP, and hope
> someone can help me.  Basically I want to store a number 

> Any thoughts?

Yes, why do you want to store the data in a text file?

Is it possible that different users of your web site might have different 
numbers at the same time?

What happens if you have 1 text file and 2 users have different numbers?

Do you want to store the number for a short period (seconds, minutes, 
maybe hours) or for longer periods (days, weeks, months)?

If you're trying to store user specific math data for a short period, the 
best storage method is probably to use the php session mechanism. This 
allows you to associate a set of data variables with each user identified 
by a session cookie on their browser (the cookie is basically a random 
number that you generate once when a user starts a session).

You then have a php superglobal array called $_SESSION which can then 
contain any named variables you wish on a per user basis.

This may be an over-simplification of php sessions, for more information 
look at the session functions especially session_start() in the php 
documentation.

http://us1.php.net/session_start

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web