使用 php 检查文本区域

发布于 2025-01-04 22:58:25 字数 165 浏览 2 评论 0原文

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

如果该字段为空>做某事.....否则>做某事...

我不擅长php,所以我会很高兴获得任何帮助。 谢谢。

ps抱歉我的英语。

I have a textarea field and want to add a text or php code when the field is empty and if the field is not empty to add another php code. For example:

if the field is empty>do something.....else>do something...

I'm not good at php, so I'll be glad for any help.
Thanks.

p.s.Sorry for my english.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绝情姑娘 2025-01-11 22:58:25

假设您通过表单发布此内容,那么您可以执行以下操作。

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

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
}

Assuming you're posting this from a form then you can do the following.

I'll write this out the long way so it's easier to understand:

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
}
や莫失莫忘 2025-01-11 22:58:25
<?php echo isset($_POST['texarea_name']) && !empty($_POST['texarea_name']) ? 'textarea not empty' : 'texarea is empty'; ?>
<?php echo isset($_POST['texarea_name']) && !empty($_POST['texarea_name']) ? 'textarea not empty' : 'texarea is empty'; ?>
删除会话 2025-01-11 22:58:25

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

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

To test if outside variable is empty or not, you can just compare it with empty string

if ( $_POST['text'] === '') {
     echo 'there was something';
} else {
     echo 'nothing to say';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文