How to read content from a parameter file and replace the value of a variable
A.TXT content is as follows
01: The Wealthy
02: General
03: poverty
C.TXT content is as follows
01: China
02: the USA
03: Germany
04: France
05: Portugal
In the PHP file
$a 1=02
$a 2=01
$a 3=03
$c 1=01
$c 2=03
$c 3=05
How do you change the variable from a to A.TXT in the rich, change the C variable to the national name?
------to solve the idea----------------------
file_get_contents function reads txt content
First explode ("\ r \ n", $txt) Branch
Traverse the previous step, then use explode to split the colon
Get an array: Array (' the ' + ' = ' rich ', ' the ' ' "
The rest is good.
------to solve the idea----------------------
This post was last edited by xuzuning on 2015-04-26 17:27:34
$a 1 = ' 02 ';
$a 2 = ' 01 ';
$a 3 = ' 03 ';
$c 1 = ' 01 ';
$c 2 = ' 03 ';
$c 3 = ' 05 ';
$na = ' a ';
Parse_str (Str_replace (': ', Php_eol), array (' = ', ' & '), file_get_contents ("data/$na. txt")), $ar);
foreach (Preg_grep ("/^ $na \d+/", Array_keys (Get_defined_vars ())) as $v) {
$ $v = $ar [$ $v];
}
$na = ' C ';
Parse_str (Str_replace (': ', Php_eol), array (' = ', ' & '), file_get_contents ("data/$na. txt")), $ar);
foreach (Preg_grep ("/^ $na \d+/", Array_keys (Get_defined_vars ())) as $v) {
$ $v = $ar [$ $v];
}
echo $a 1, php_eol;
echo $a 2, php_eol;
echo $a 3, php_eol;
echo $c 1, Php_eol;
echo $c 2, Php_eol;
echo $c 3, Php_eol;
So so
Rich
Poor
China
Germany
Portugal
Your plan is wrong, it's impossible to get good performance