たとえば、私はphpにそのような文字列を持っています:
$str='<img title="title of image" src="../somepic.gif" alt="some pic image" class="someclass" style="somestiles" onload="alert(this)" />';
//it can be anything: '<br>123<P><script>' or '123</script>' (even with newlines \r and \n and other special symbols)
そして、クリックした後にのみ表示する必要があります。
<?php
echo'<div>
<textarea onclick="this.parentNode.innerHTML=this.value">',htmlspecialchars($str),'</textarea>
</div>';
?>
ご覧のとおり、jsはtexarea要素を$ str変数に格納され、「<textarea>」値にテキストとして配置されたものに置き換えます。
JSのデータを保存するためにtextarea要素を使用せずにこれを実現する方法を知る必要があります。(現在、非表示のテキスト領域を使用していますが、そのような方法が正しいとは思えません)