php - 使用onClick作为字符串设置html超链接

any ideas why this does not work?

$pem = 'hello';
$view_pem = "<a onClick='function('<?php echo $pem ?>');'>View PEM</a>";

echo $view_pem;

I simply want to use onClick to echo a string but im unable to make it work. With the above code, my link ends up looking like this ?>')'>View PEM and doesnt work.

I also tried putting the php tag inside double quotes but then it complains Parse error: syntax error, unexpected '?'

hopefully this is an easy fix?

Use this

      $pem = 'hello';
      $view_pem = "<a onClick='function(\"$pem\")' href='javascript:void(0);'>View PEM</a>";

       echo $view_pem;