gpt4 book ai didi

php - 为什么在文本区域中生成以下通知?

转载 作者:可可西里 更新时间:2023-11-01 00:08:16 25 4
gpt4 key购买 nike

为什么文本区会出现如下提示?在本地机器上运行 php 文件后。

这是带有屏幕截图的通知: schema

图中注意:

Notice: Undefined variable: user_input in C:\xampp\htdocs\PhpProject1\index.php on line 15

这是我用 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>

最佳答案

您收到通知是因为 $user_input; 未定义,因为 POST['user_input'] 未设置。为避免通知打印 $user_input; 仅当已定义时

echo isset($user_input) ? $user_input : '';

因为你在 textarea 中打印 $user_input 所以错误在那里打印

关于php - 为什么在文本区域中生成以下通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42364924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com