PHP将<option>数据加载到<textarea>中

Kyl*_*yle 0 php

<select name="template" id="template">
        <option value="none">Don't use template</option>
        <option value="RWT">Report Abuse</option>
        <option value="renew">Resend Email Codes</option>
    </select><br/>
    <textarea name="body" rows="10" id="content" value="<?php echo $body;?>"ondblclick="select_all('content');" cols="40"></textarea><br/>
Run Code Online (Sandbox Code Playgroud)

....

else if ($template == "renew") {
        $body = "Dear $username,<br/></br/>";
        $body .= "Here is your requested activation code: $activationID <br/><br/>";
        $body .= "Thank you.<br/>";
    }
Run Code Online (Sandbox Code Playgroud)

当我选择"续订"选项时,它不会将数据加载到我的textarea中.如何在textarea中加载选项数据?

Jon*_*Jon 5

它必须进入textarea标签:

<textarea name="body" rows="10" id="content" ondblclick="select_all('content');" cols="40">
  <?php echo $body;?>
</textarea>
Run Code Online (Sandbox Code Playgroud)

更新:正如评论中提到的那样,echo htmlspecialchars($body)会更好,因为这是正确的做事方式 - 在这种特定情况下没有区别,但除非您这样做,否则您的应用程序将容易受到XSS攻击.