简体   繁体   English

使用$ _POST php调用变量

[英]call variable using $_POST php

<body onload="cmdform.command.focus()">
<form method="POST" action="#" name="cmdform">
<textarea style="width:100%; height:90%; background:black; color:green;" name="textarea" cols="20" >
<?php 
$name="My Name";
if (isset($_POST['submit'])){
    if (!empty($_POST['command'])){
        echo $me = $_POST['textarea'];
        echo "\n";
        echo $_POST['command'];
    }else{
        echo $me = $_POST['textarea'];
    }
}
?>
</textarea>
<input type="text" name="command">
<input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="B2">
</form></body>

When I enter $name in textbox("command") 'My Name' should display in textarea 当我在textbox(“ command”)中输入$ name时,“ My Name”应显示在textarea中

You can solve this with a simple str_replace() call. 您可以通过简单的str_replace()调用解决此问题。

$content = str_replace('$name', $name, $content);

Or you use an if() statement to check if the content is exactly the string "$name" . 或者,使用if()语句检查内容是否恰好是字符串"$name"

if ($_POST['command'] == '$name') {
    $content = $name;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM