Write an array to the configuration file. Why does the symbol become &

Source: Internet
Author: User
Write an array to the configuration file. Why does the & symbol change to & amp; $ config_arr = var_export ($ configdata, true );
$ Config_txt =" File_put_contents ('config. ini. php', $ config_txt );


$ Config_arr is an array with the & symbol in the array value. after writing it to config. ini. php, the & symbol becomes &

Is there a way to keep it unchanged?


Reply to discussion (solution)

This is impossible. it should have been the beginning of your html escape.

$a = array('a' => '&abc');$s =  var_export($a, 1);echo $s;
array (  'a' => '&abc',)

It is possible that the & in your array is an object before writing. Print_r ($ configdata); check the source code.

You have escaped before.

You can use htmlspecialchars_decode to return.
Http://php.net/manual/en/function.htmlspecialchars-decode.php

Before writing, I use print_r to output the result as follows:


The result after the file is written is as follows:


This is the source code:

No html conversion is performed before writing.

This is the source code

After printing it out, check the source code in the browser to see if there is any conversion.

This problem is solved by escaping characters when receiving parameters.
There is another problem:
The configdata array contains the character backslash \. after this sentence
$ Config_arr = var_export ($ configdata, true );

After being written to the configuration file, the backslash becomes \. how can this problem be solved?

#4 display results in html mode
Right-click the source file to view the real data.
Or output before printing.

Mark <br/> echo '<xmp>'; <br/> print_r ($ config_arr ); </p> <p class = "sougouAnswer"> <p class = "yy"> The problem is solved, the character is escaped when parameters are received. <br/> now there is another problem: <br/> The configdata array contains the character backslash \, after this sentence, <br/> $ config_arr = var_export ($ configdata, true ); <br/> after being written to the configuration file, the backslash becomes \. </p> <br/> stripslashes () use this method to go back.

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.