Correct combination of escape characters to inject PHP in javascript? -
i've tried combination know of can't right!
echo <<<eof <a href="javascript:popup('$comments')">popup!</a> eof;
i want pass string contained in $comments popup, can't seem right combination of escape characters , concatenation. pls!
tia
edit: html goes string mentioned.
$comments.= "<b>" . $row['comname'] . "</b><br><i>" . $row['comment'] . "</i><br><br>";
you need escape string valid javascript/json first preserve javascript syntax, escape javascript preserve syntax of html it's embedded in:
$js = sprintf('javascript:popup(%s)', json_encode($comments)); printf('<a href="%s">popup!</a>', htmlspecialchars($js));
since quite pain, should try go unobtrusive javascript, separates javascript html.
Comments
Post a Comment