我是初学者和自学者。这可能是一个简单的问题,但它给我带来了一些问题。我想我错过了某个地方。
当我在textarea
中编写一些文本并点击查找和替换按钮(将其他两个字段留空)时,textarea
中捕获的值应出现在textarea
本身和错误消息中应出现在textarea
之外。 textarea
不应该是空白的。我认为消息工作正常。
我不确定按钮或操作是否出现问题=''形式。
<?php
//find and replace string
//using str_replace(), takes three parameters, $findword, $wordtoreplace, $userinput
if(isset($_POST['text']) && isset($_POST['find']) && isset($_POST['replace'])){
$paragraph=nl2br(htmlentities($_POST['text']));
$find_string=$_POST['find']; //assign the value to be found to the variable
$replace_string=$_POST['replace']; //assign the value to be replaced
if(empty($paragraph)){
echo 'No text to search for.';
}
elseif(empty($find_string)){
echo 'Enter some text to find.';
}
elseif(empty($replace_string)){
echo 'Enter some text to replace with.';
}
else{
echo str_replace($find_string, $replace_string, $paragraph);
}
}
?>
<form action='' method='POST'>
<textarea name='text' rows=20 cols=100 value='<?php echo $paragraph; ?>'></textarea
<br />
<label>Search For</label>
<input name='find' value='<?php echo $find_string; ?>'></input>
<br />
<label>Replace with</label>
<input name='replace' value='<?php echo $replace_string; ?>'></input>
<br />
<button>Find and Replace</button>
</form>
答案 0 :(得分:3)
<textarea>
没有value
属性。提供如下内容:
<textarea name='text' rows='20' cols='100'><?php echo $paragraph; ?></textarea>
顺便说一下,</textarea
的结束括号
答案 1 :(得分:1)
您必须将输出放在textarea的中间打开和关闭标记:
<textarea name='text' rows=20 cols=100><?php echo $paragraph; ?></textarea>