问题描述
我是 PHP 的学习者,我有一段代码,我在其中实现了 HTML5 代码.我想要做的是在我的占位符中嵌入内联三元运算符.
I am a learner in PHP, and I have a code in which I am implementing HTML5 code. What I am trying to do is to embed the inline ternary operator in my placeholder.
我已经点击了这个链接,但没有一个有相同的问题陈述:
I have followed this link, but none of them are having same problem statement:
我的代码:
echo "<input type='text' class='form-control' value='".$value."' placeholder='HERE I WANT TO OPERATE'>";
尝试过:我已经在我的代码中尝试过这个,但出现错误
Tried: I have tried this in my code, but I am getting errors
echo "<input type='text' class='form-control' value='".$value."' placeholder='"empty($value) ? 'Some Text' : 'Enter Data';"'>";
我知道如何在PHP的echo code
之外进行三元运算,但我正在寻找这种方式.
I know how to do the ternary operation outside the echo code
in PHP, but I am looking for this way.
推荐答案
三元运算将返回一个字符串.因此,它必须连接到字符串的其余部分.
The ternary operation will return a string. As such, it has to be concatenated to the rest of the string.
echo "<input type='text' class='form-control' value='".$value."' placeholder='". (empty($value) ? 'Some Text' : 'Enter Data') ."'>";
这篇关于在 PHP 中嵌入 HTML 中实现内联三元运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!