Implement inline ternary operator in embedded HTML in PHP

Alok :

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:

  1. Putting inline style using ternary operator php
  2. Inline PHP/HTML Ternary If

My Code:

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';"'>";

I know how to do the ternary operation outside the echo code in PHP, but I am looking for this way. Any help would be appreciated.

wxker :

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') ."'>";

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=33089&siteId=1