0

私は初心者で自己学習者です。これは簡単な質問かもしれませんが、私にはいくつかの問題が生じています。私はどこかで何かを逃したと思います。

テキストを書き込んでtextarea[検索と置換] ボタンを押すと (他の 2 つのフィールドは空のままにしておきます)、キャプチャされた値はそれ自体にtextarea表示され、textareaエラー メッセージは の外側に表示されますtextareatextarea空白にしないでください。メッセージはうまく機能していると思います。

問題がボタンにあるのか、フォームの 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>
4

2 に答える 2

3

<textarea>value属性を持っていません。次のようなコンテンツを提供します。

<textarea name='text' rows='20' cols='100'><?php echo $paragraph; ?></textarea>

Btw, the closing bracket of </textarea was missing

于 2013-11-11T15:53:10.780 に答える
1

出力をテキストエリアの開始タグと終了タグの中間に配置する必要があります。

<textarea name='text' rows=20 cols=100><?php echo $paragraph; ?></textarea>
于 2013-11-11T16:46:57.960 に答える