gpt4 book ai didi

Php 编写编辑过的脚本文件内容导致额外的换行符

转载 作者:行者123 更新时间:2023-12-04 05:30:32 25 4
gpt4 key购买 nike

在一个多语言站点中,我有两个包含 php 常量的 php 文件。

喜欢

定义('电子邮件','电子邮件');
定义('性别','性别');
.
.

.

我使用表单中的文本区域从管理端提供对这些文件的编辑。在 textarea 中打印完整文件。
当管理员更新文件时,它会导致重定向问题,这意味着在包含此文件 header() 函数后无法报告上面的非空白字符。

我在编辑后检查了 php 文件,它在每个 php 语句之间包含了很多额外的空间,如下所示,

定义('电子邮件','电子邮件');

定义('性别','性别');

定义('名字','名字');

一条长的单行也分成多行,比如。

define('SENTENCE', '这是一个很长的句子,
正如我所指出的那样,根据文本区域的宽度分成多行');


所以这也会导致错误,因为它必须在单行中

我确信这些额外的空格和换行符是所有问题的原因。我在 textarea 之间的打印中使用此代码:

<textarea  style="width: 664px; height: 353px;" id="edit_file" name="edit_file"><?php
$file = fopen("../en.php", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file);
}
fclose($file);
?> </textarea>

和保存文件:
if(isset($_POST['btn']) && $_SERVER['REQUEST_METHOD']=='POST' && !empty($_POST['btn'])){
if (get_magic_quotes_gpc()) {
$filedata = stripslashes($_POST['edit_file']);
}
$filedata=str_replace(array("<br />'",'\n'),array("",''),$filedata);
$size=strlen($filedata);
$file = fopen("../en.php", "w") or exit("Unable to open file!");
fwrite($file,"$filedata",$size);
fclose($file);
}

最佳答案

有 1 个意外引号,\n 不能放在简单引号内:

$filedata=str_replace(array("<br />'",'\n'),array("",''),$filedata);

替换为:
$filedata=str_replace(array("<br />","\n"),array("",''),$filedata);

关于Php 编写编辑过的脚本文件内容导致额外的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12685192/

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