<?php
if (isset($_POST['sub'])) {
$txt = $_POST['txt'];
//注意Windows文本文档的换行是"/r/n"
//方法一
$a=file_get_contents("hexie.txt");
$arr_grep=explode("/r/n",$a);
//方法二
/*
$arr=file("hexie.txt");
foreach($arr as $key=>$value)
{
$arr_grep[$key]=rtrim($value,"/r/n");
}
*/
$replace="**";
$txt =str_replace($arr_grep,$replace,$txt,$count);
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>和谐神器</title>
</head>
<body>
<form method="post">
<div align="center">
<table>
<tr >
<td colspan="4" align="center"><font color="red"size="35px">和谐神器</font></td>
</tr>
<tr>
<td><b>请输入文章:</b></td>
<td><textarea name="txt" cols="30" rows="15">
<?php echo @$_POST['txt']; ?>
</textarea></td>
<td><b>和谐后文章:</b></td>
<td><textarea name="txt_hou" cols="30" rows="15">
<?php echo @$txt; ?>
</textarea></td>
</tr>
<tr >
<td colspan=4 align="center"><input type="submit" name="sub" value="开始和谐" />
<?php if(isset($_POST['sub'])){echo "共和谐了".$count."处<br />";} ?>
</td>
</tr>
</table>
</div>
<hr />
</form>
</body>
</html>