用php检查文本区域


Check textarea with php

我有一个文本区域字段,当该字段为空时,我想添加一个文本或php代码,如果该字段不为空,则添加另一个php代码。例如:

如果字段为空>做点什么。。。。。其他>做点什么。。。

我不擅长php,所以我很乐意得到任何帮助。谢谢

p.s.对不起我的英语。

假设您是从表单中发布的,那么您可以执行以下操作。

我会把它写得很长,这样更容易理解:

if (!empty($_POST['TEXTAREA_NAME']){
     // If the textarea is set then do something here
} else {
     // If it is NOT set it then it will do the code here
}
<?php echo isset($_POST['texarea_name']) && !empty($_POST['texarea_name']) ? 'textarea not empty' : 'texarea is empty'; ?>

要测试外部变量是否为空,只需将其与空字符串进行比较

if ( $_POST['text'] === '') {
     echo 'there was something';
} else {
     echo 'nothing to say';
}