How to read content from a parameter file and replace the value of a variable

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.