0

What is wrong with the following code, that I produced for testing the content of the button?

I get the syntax error "unexpected 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>

Thank you!

1
  • 1
    looks like the problem is in the argument list for window.open. all the single quotes should probably be escaped. also deosn't look like you're using any php inside the print() why use it at all? Commented Sep 14, 2013 at 9:17

4 Answers 4

1

Your quotes are not properly escaped. There are several ways to fix this.

Heredoc:

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;

Escaping:

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>                                                   
';
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to use ' inside of ', you got to escape them.

// "usual" string
$foo = 'abc';
// string with ' as content
$bar = ' abc \' def ';

In your example, have a look at the call to window.open().

<?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>                                                   
    ';
?>

For a cleaner code base you should move that code to a separate function in your already existing <script> tag and just reference this in the button. (or add the event using addEventListener() in JavaScript)

3 Comments

Any difference ? use ' inside of '. Don't get you.
@SilverBlade If you define a string by using ', it looks like this $foo = 'abc';. If you want to use any ' inside that string, you have to escape it like this $bar = ' abc \' def ';.
Ok got you. +1 to this :)
0

you have an extra ' before toolbar=0 'toolbar=0

remove and it should be fine

Comments

0

You need to escape the double quote as: \" instead of ""

An un-escaped " will prematurely terminate the string.

Example:

This is incorrect: "k " is a double quote"

This is correct: "k \" is a double quote"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.