用户输入数据与原始数据对比,然后输出不同数据的提示。
PHP 、JS、JQuery 都行,哪种简单用那种,谢谢![代码]<style type="text/css">
iframe,textarea,#output,input { width:250px; float:left; height:500px; margin-right:50px; border:1px solid #000}
textarea { overflow-x:hidden;overflow-y:hidden}
#output { height:450px }
input { height:40px; margin-top:10px}
</style><iframe src="cfg.txt" id="source" frameborder="0" border="0" cellspacing="0"></iframe>
<textarea></textarea>
<div id="output"></div>
<input type="submit" name="check" id="check" value="检测按钮" />
PHP 、JS、JQuery 都行,哪种简单用那种,谢谢![代码]<style type="text/css">
iframe,textarea,#output,input { width:250px; float:left; height:500px; margin-right:50px; border:1px solid #000}
textarea { overflow-x:hidden;overflow-y:hidden}
#output { height:450px }
input { height:40px; margin-top:10px}
</style><iframe src="cfg.txt" id="source" frameborder="0" border="0" cellspacing="0"></iframe>
<textarea></textarea>
<div id="output"></div>
<input type="submit" name="check" id="check" value="检测按钮" />
$arStandard = array(
'red' => '"0"',
'blue' => '"1"',
'gray' => '"2"',
'green' => '"3"',
'yellow' => '"1"');
$str =
'blue "1"
gray "2"
green "3"
red "1"
yellow "1"
orange "xx"'; //这是POST过来的用户输入数据//将用户输入数据格式化为一个关联数组,存入$arInput
$arInput = $arTMP = array();
foreach(split("[\r\n]+",$str) as $v) {
$arTMP = preg_split("/[\s]+/",$v);
$arInput[$arTMP[0]] = $arTMP[1];
}$arToDelete = $arIncorrect = array();
foreach($arInput as $k => $v) {
if (!array_key_exists($k,$arStandard)) $arToDelete[$k] = $v;
else {
if ($v != $arStandard[$k]) $arIncorrect[] = $k;
}
}//输出
echo "<pre>";if (count($arToDelete) > 0) {
echo "请删除以下数据:\n";
foreach($arToDelete as $k => $v) echo "{$k} {$v}\n";
}
if (count($arIncorrect) > 0) {
echo "下面数据请修改成:\n";
foreach($arIncorrect as $v) echo "{$v} {$arStandard[$v]}\n";
}
我的问题 :) ,还是不太懂:index.html 的代码如下:<form action="" method="post" name="form" id="form">
<textarea></textarea>
<input type="button" name="Submit" value="提交" onclick="document.form.action='post.php';document.form.submit();" />
</form>
post.php 的代码用你提供的,其中:$str =
'blue "1"
gray "2"
green "3"
red "1"
yellow "1"
orange "xx"'; //这是POST过来的用户输入数据
这里应该修改什么样式? $str = 'textarea'; //乱撞的,不行
$str = '$_POST'; //乱撞的,不行2请指教,不甚感激!
'red' => '"0"',
'blue' => '"1"',
'gray' => '"2"',
'green' => '"3"',
'yellow' => '"1"');
$str =
'blue "1"
gray "2"
green "3"
red "1"
yellow "1"
orange "xx"'; //这是POST过来的用户输入数据preg_match_all("/(\S+)\s+(\"\S+\")/iU",$str,$match);
$arr = array_combine($match[1],$match[2]);
$diff = array_diff_assoc($arr,$arStandard);var_dump($diff);
if (isset($_POST['t'])) $str = $_POST['test'];
?>
<form action="./" method="post" name="form" id="form">
<textarea name="test"></textarea>
<input type="button" name="Submit" value="提交" onclick="document.form.action='post.php';document.form.submit();" />
</form>
谢谢解答,还有一个小小的疑问,如果要忽略检测 red "0" ,呢?
echo "请删除以下数据:\n";
foreach($arToDelete as $k => $v) echo "{$k} {$v}\n";
}中显示,忽略检测 red 数据的值。