gpt4 book ai didi

php - file_put_contents 正在向代码添加反斜杠

转载 作者:行者123 更新时间:2023-12-01 23:12:04 24 4
gpt4 key购买 nike

我使用 file_get_contents()file_put_contents() 加载和保存 .css 文件。保存加载的文件后,file_put_contents() 函数将对引号进行转义,如何避免这种情况。

$file = 'pathto/base.css';

$ta = $file_get_contents($file);// load

<textarea name="editor"><?php echo $ta;?></textarea>

// press submit button here

file_put_contents($file, $_POST['editor']);// save

// new css code will be something like this

.row:after{
content:/"/";// not what we need

}

最佳答案

很可能你有 Magic Quotes开启。

所以只需在 php.ini 中将其关闭并重新启动 PHP。


去除斜线:

file_put_contents($file, stripslashes($_POST['editor']));

关于php - file_put_contents 正在向代码添加反斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22797266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com