For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > February 2007 > a variable can to be used in every place









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author a variable can to be used in every place
den

2007-02-23, 7:59 am

If I have in this dir :\AA\BB\E\F\G\H\I\
one file.php with this variable:
$pip['value']=50;

If I want to use in other dir's file \AA\BB\CC\

1) is possible?
but I not want to require or include the file.php.
I would like use directly the variable.


Steve Belanger

2007-02-23, 7:01 pm

one way you could do that is to save the variable into the user sessions and
retreive it with $_SESSION or something of that nature.


"den" <spamnot@not.not> wrote in message
news:f02k3n8x5y1b$.1g8bypxw8ag0b.dlg@40tude.net...
> If I have in this dir :\AA\BB\E\F\G\H\I\
> one file.php with this variable:
> $pip['value']=50;
>
> If I want to use in other dir's file \AA\BB\CC\
>
> 1) is possible?
> but I not want to require or include the file.php.
> I would like use directly the variable.
>
>



shimmyshack

2007-02-23, 7:01 pm

On 23 Feb, 10:25, den <spam...@not.not> wrote:
> If I have in this dir :\AA\BB\E\F\G\H\I\
> one file.php with this variable:
> $pip['value']=50;
>
> If I want to use in other dir's file \AA\BB\CC\
>
> 1) is possible?
> but I not want to require or include the file.php.
> I would like use directly the variable.


you have to open the file though right?
so unless you treat it as atext file, and have the file like this:
$pip['value']=50;
$pip['value2']=150;
$pip['value3']=150;
and use file() to get an array, and split to by = ...
or use regular expressions to extract the key=>values

the easiest way is to include it, unless there's some reason you
can't:

file.php:

<?php
return array
(
'pip' => array
(
'host' => 'localhost',
'user' => 'me',
'pass' => 'strong_3st_in-the-wORld!',
'db' => 'cheese',
'value' => 50,
)
);
?>

then in which file you need it, use
$arrayInfo = include( 'file.php' );
print_r( $arrayInfo );

but i understand it might not be what youre after

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com