我为测试按钮内容而生成的以下代码有什么问题?
我收到语法错误“意外的 T_CONSTANT_ENCAPSED_STRING”
<?php /* Created on: 14-9-2013 */ ?>
<html>
<head>
<script type="text/javascript" charset="utf-8">
var mldkr = Math.round(screen.availWidth/2.08);
var supro = Math.round((screen.availHeight)/6), alto=supro*4
var urlesp = "http://translate.google.com/#<?php echo $fontLingvo ?>|eo|<?php echo $fontVorto ?>";
</script>
</head>
<body>
<table>
<?php
print '
<tr height="30">
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td align="right">
<button type="button" onclick="fenEspo = window.open(urlesp, '', 'toolbar=0, location=0, directories=0, menuBar=0, scrollbars=1, resizable=1, height='+alto+', top='+supro+', left='+mldkr+', width='+mldkr, true)" title="Ne gravas, ne kalkuliĝas por la statistiko.">Kaj kion donas Gugl Trenslejt kiel<br />traduko(j)n por Esperanto?</button>
</td>
<td align="center">
<input type="radio" name="eo" value="1" />jes
<input type="radio" name="eo" value="0" />ne
<input type="radio" name="eo" value="-1" disabled="disabled" /><font size="-3">ne aferkoncerna</font>
</td>
</tr>
'
?>
</table>
</body>
</html>
谢谢!
最佳答案
您的引号未正确转义。有几种方法可以解决这个问题。
定理:
print <<<EOT
<tr height="30">
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td align="right">
<button type="button" onclick="fenEspo = window.open(urlesp, \'\', \'toolbar=0, location=0, directories=0, menuBar=0, scrollbars=1, resizable=1, height=\'+alto+\', top=\'+supro+\', left=\'+mldkr+\', width=\'+mldkr, true)" title="Ne gravas, ne kalkuliĝas por la statistiko.">Kaj kion donas Gugl Trenslejt kiel<br />traduko(j)n por Esperanto?</button>
</td>
<td align="center">
<input type="radio" name="eo" value="1" />jes
<input type="radio" name="eo" value="0" />ne
<input type="radio" name="eo" value="-1" disabled="disabled" /><font size="-3">ne aferkoncerna</font>
</td>
</tr>
EOT;
转义:
print '
<tr height="30">
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td align="right">
<button type="button" onclick="fenEspo = window.open(urlesp, \'\', \'toolbar=0, location=0, directories=0, menuBar=0, scrollbars=1, resizable=1, height=\'+alto+\', top=\'+supro+\', left=\'+mldkr+\', width=\'+mldkr, true)" title="Ne gravas, ne kalkuliĝas por la statistiko.">Kaj kion donas Gugl Trenslejt kiel<br />traduko(j)n por Esperanto?</button>
</td>
<td align="center">
<input type="radio" name="eo" value="1" />jes
<input type="radio" name="eo" value="0" />ne
<input type="radio" name="eo" value="-1" disabled="disabled" /><font size="-3">ne aferkoncerna</font>
</td>
</tr>
';
关于javascript - 无法在 php print 中获得 JavaScript 变量的正确语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18800186/