私は初心者で自己学習者です。これは簡単な質問かもしれませんが、私にはいくつかの問題が生じています。私はどこかで何かを逃したと思います。
テキストを書き込んでtextarea
[検索と置換] ボタンを押すと (他の 2 つのフィールドは空のままにしておきます)、キャプチャされた値はそれ自体にtextarea
表示され、textarea
エラー メッセージは の外側に表示されますtextarea
。textarea
空白にしないでください。メッセージはうまく機能していると思います。
問題がボタンにあるのか、フォームの action='' にあるのかわかりません。
<?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>