Re: looping variables from a file

From: Date: Wed, 24 Mar 2004 17:42:42 +0000
Subject: Re: looping variables from a file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-181382@lists.php.net to get a copy of this message
From: "Ryan A" <ryan@coinpass.com> > I have a config_inc.php file which has around 60 parameters set in it. > eg: > $db_name="something"; > $db_user="root"; > $db_pass="blah"; > $x_installed_path="/home/blah/"; > etc > > I have a requirment of echoing out these statements to the client to show > him how his setup is: > > eg: > echo "DB_name=<font color green>".$db_name."</font>"; One idea is to just fopen() the actual file (not the resulting PHP, which will be empty), and do some str_replaces to add in the <font> tags, etc. The rules for that could get tricky, though. Another option is to use get_defined_vars() before you include the file (saved into $array1), then save the results again after you include the file and create the new variables (saved into $array2). Now use array_diff($array2,$array1) to find the variables that were added. Now loop through those with foreach() and apply the formatting. Isn't PHP fun!? ---John Holmes...

« previous php.general (#181382) next »