当前位置: 动力学知识库 > 问答 > 编程问答 >

Multiple layers of quotes in script in PHP variable that is echoed

问题描述:

PHP:

$var123 = '<div class="mydiv" onclick="document.getElementById("dialog").style.display = "block";">Some text</div>';

echo($var123);

I know this is a total newbie question, but how do I make this work? Thanks!

网友答案:

You can use single quotes in Javascript. Since your string is enclosed in single quotes you also need to escape them in PHP with a backslash \.

$var123 = '<div class="mydiv" onclick="document.getElementById(\'dialog\').style.display = \'block\';">Some text</div>';
echo $var123;
网友答案:
$var123 = 'Some text';
<div class="mydiv" onclick="document.getElementById("dialog").style.display = "block";">
<?php echo $var123; ?>
</div>;

Try this

分享给朋友:
您可能感兴趣的文章:
随机阅读: