Complicated case of escaping quotation marks
Here is the code I am trying to make work. As you can see, the code as it stands will call a javascript window and that works well. I now want to add the lines that are commented out, in order to make the window display or not display conditionally. I have tried many combinations of escaping quotation marks, or substituting them, but nothing works properly. Usually I lose the link action along with a display of some of the code attached to the link. Could someone have a look and see if they can propose a code solution.
<?php
//if ($review != 0)
//$yes2 =
if ("{$row['passState']}" == 0) {echo "<a href='javascript<b></b开发者_如何学Python>:void(0);'NAME='var basestring='window'+new Date().getTime();' title=' Results of quiz 'onClick=window.open('check/check.php?quizTitle=". urlencode($quizTitle) ."', 'width=1100, height=510, resizable=yes, menubar=no, status=0, scrollbars=1');> <p>Check your answers</p> </a><br />\n";}
//echo $yes2;
//if ($review != 1)
//echo "";
?>
If it is any help, I'm using this code elsewhere on the page and it works fine.
<?php
if ($review != 0)
$yes2 = "REVIEW";
echo $yes2;
if ($review != 1)
echo "";
?>
if ("{$row['passState']}" == 0) {echo "<a href='javascript<b></b>:void(0);' NAME=\"var basestring='window'+new Date().getTime();\" title=' Results of quiz ' onClick=window.open('check/check.php?quizTitle=\". urlencode($quizTitle) .\"', 'width=1100, height=510, resizable=yes, menubar=no, status=0, scrollbars=1');> <p>Check your answers</p> </a><br />\n";}
Copy this as it is....
There's no need for all the escapes, you should embed the PHP code in the HTML, not the other way around. Example:
<?php if ($row['passState'] == 0): ?>
<p>
<a href="javascript:your_code()">
Check your answers
</a>
</p>
<br />
<?php endif; ?>
I had a hard time deciphering what your javascript was trying to actually do, but this will make it a lot easier for you to read and write HTML without worrying about escaping quotes, using \n
characters, etc.
http://php.net/manual/en/control-structures.alternative-syntax.php
You can use addslashes method to escape quotes
PHP Manual
Your onClick needs to have a quote(s) after the =
:
...f quiz' onClick=\'window.open('check/check.php?quizTitle=". urlencode($quizTitle) ."',
精彩评论