PHP変数の一部を取り入れる必要があるHTML文字列を書いています。しかし、二重引用符を正しくエスケープすることはできません。PHP変数を含むHTML文字列を引用符で囲む正しい方法
試み1:
$html .= '<span class="badge"><a href="#" style="color:orange"><span class="glyphicon glyphicon-arrow-up" aria-hidden="true" onclick="sendToProduction(\''.$configType.'\')"></span></a></span>';
結果:
<span class="glyphicon glyphicon-arrow-up" aria-hidden="true" onclick="sendToProduction(\' project\')"=""></span>
試み2:
$html .= '<span class="badge"><a href="#" style="color:orange"><span class="glyphicon glyphicon-arrow-up" aria-hidden="true" onclick="sendToProduction('.'$configType'.')"></span></a></span>';
結果:
<span class="glyphicon glyphicon-arrow-up" aria-hidden="true" onclick="sendToProduction(project)"></span>
閉じるが、'project'
でなければなりません。
望ましい結果:
<span class="glyphicon glyphicon-arrow-up" aria-hidden="true" onclick="sendToProduction('project')"></span>
私はそれをテストしたときに最初の試みがうまくいきました。 – Xposedbones