javascript - 无法在 php print 中获得 JavaScript 变量的正确语法

标签 javascript php

我为测试按钮内容而生成的以下代码有什么问题?

我收到语法错误“意外的 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&#285;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&#285;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&#285;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/

相关文章:

javascript - 为什么使用 body 解析器未定义 req.body ?

javascript - 如何在谷歌柱形图中添加轴刻度/标签?

php - 使用 jQuery : Is 'https' enough to secure the XML? 从 PHP webservice 调用解析 XML

php - 图像未在 MySQL 中上传

javascript - 在 Chrome 开发工具中使用词法作用域(闭包)调试 angularjs 指令时出现奇怪的行为

javascript - 如何访问 *ngFor 中定义的变量?

javascript - 如何让我的动画技能栏响应

php - 非主键自增字段

php - 超过 100 个名称的 var,检查文本中是否存在任何名称

php - preg_match 的问题