I have a php variable like this

$opensslOut = preg_replace('/\n\r{0,1}/', '<br>', $str);

I need to print its value on a form element. I used the following code

$form['openssl'] = [
      '#title' => t('OpenSSL'),
      '#markup' => t('$opensslOut'),

But didn't worked? I am a newbie in Drupal, Please help me to figure out a solution.

  • It seems, you are not only newbie in drupal, php as well as, Don't signle/dobule quotes for variables, It would handle as string :) – Leopathu Jul 20 '16 at 7:05
  • Welcome to Drupal Answers! This is a plain PHP question. If you need to pass to t() the content of $opensslOut, you simply use t($opensslOut). Since Drupal doesn't change the PHP syntax, this question is off-topic for us. Also, notice that you don't pass to t() the content of a variable, since the first argument of t() needs to be a literal string. – kiamlaluno Jul 20 '16 at 8:13

It's just a silly error '#markup' => t('$opensslOut') needs to be without the '' because $opensslOut is a variable and not a string.

So use

'#markup' => t($opensslOut)

| improve this answer | |

The answer is simple.Just remove the quotes of $opensslOut.

$form['openssl'] = [ '#title' => t('OpenSSL'), '#markup' => t($opensslOut), ];

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.