将提交的文本区域与初始值进行比较
Compare submitted textarea with initial value
我想将数组(从文本文件)输出到文本区域,让用户更改它,然后将该数组保存回文本文件。
<textarea name="text"><? echo(html_entity_decode(implode("\n", $array))) ?></textarea>
在将数组存储回文本文件之前,我想确定是否确实发生了某些更改。
if ($_POST['text'] != html_entity_decode(implode("\n", $array))) {
// SAVE THE TEXT BACK TO THE FILE
}
但上述条件总是returnstrue
,即使没有提交更改。
我做错了什么?提交时是否对输入进行了其他处理?
也许试试
if(strcmp(preg_replace( "/\r|\n/", "", $_POST['text']), html_entity_decode(implode("\n", $array))) != 0){
// SAVE THE TEXT
}
这有点难以阅读,但本质上 preg_replace 应该从 POST 数据中去除换行符,以便将其与原始数组进行比较。希望这对你有用!
我想将数组(从文本文件)输出到文本区域,让用户更改它,然后将该数组保存回文本文件。
<textarea name="text"><? echo(html_entity_decode(implode("\n", $array))) ?></textarea>
在将数组存储回文本文件之前,我想确定是否确实发生了某些更改。
if ($_POST['text'] != html_entity_decode(implode("\n", $array))) {
// SAVE THE TEXT BACK TO THE FILE
}
但上述条件总是returnstrue
,即使没有提交更改。
我做错了什么?提交时是否对输入进行了其他处理?
也许试试
if(strcmp(preg_replace( "/\r|\n/", "", $_POST['text']), html_entity_decode(implode("\n", $array))) != 0){
// SAVE THE TEXT
}
这有点难以阅读,但本质上 preg_replace 应该从 POST 数据中去除换行符,以便将其与原始数组进行比较。希望这对你有用!