0

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.

closed as off-topic by Clive Jul 20 '16 at 7:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on programming, PHP, SQL, etc. that do not relate directly to Drupal are off-topic here, but can be asked on Stack Overflow." – Clive
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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
2

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)

1

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

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

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