为什么在文本区域生成以下通知?在本地机器上运行php文件之后。为什么在textarea中生成以下通知?
这里是与屏幕截图中的通知:
通知在图像中:
通知:未定义变量:USER_INPUT在C:\ XAMPP \ htdocs中\ PhpProject1 \索引。 php on line
这里是我的代码,我在NetBeans我书面方式:
<?php
$find= array('alex','billy','dale');
$replace=array('a**x','b***y','d**e');
if(isset($_POST['user_input'])&&!empty($_POST['user_input'])){
$user_input = $_POST['user_input'];
$user_input_new= str_ireplace($find, $replace, $user_input);
echo $user_input_new;
}
?>
<hr>
<form action="index.php" method="POST">
<textarea name="user_input" rows="6" cols="30">
<?php
echo $user_input;
?>
</textarea><br><br>
<input type="submit" value="submit">
</form>
在PHP7中,你也可以使用[null coalescing operator](http://php.net/manual/en /migration70.new-features.php#migration70.new-features.null-coalesce-op):'echo $ user_input ?? '';' – Gondrup
是的,这是正确的,但我不知道OP使用的是什么版本,所以我更喜欢用这种方式 – Fabio
同意你的方式是向后兼容的更安全的选择。 – Gondrup