php - How to fix file_put_contents execution failure when it contains & symbol?
滿天的星座
滿天的星座 2017-05-16 13:13:03
0
3
713

The execution is successful like this:
<?php
$filename="test.txt";
file_put_contents($filename, "nihao");
?>

But this will fail:
<?php
$filename="test.txt";
file_put_contents($filename, "ni&hao");
?>

Please give me some advice. There is just an extra and symbol. How should I deal with this?

滿天的星座
滿天的星座

reply all(3)
迷茫

"ni&hao" Add the escape character '&' before special characters or change the double quotes to single quotes.

迷茫

Is it possible? I have tested both methods and both are fine.

刘奇
<?php
$filename="test.txt";
file_put_contents($filename, json_encode("ni&hao"));
?>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template