I have what is, for me, quite a complex line I want to parse into php.
echo '<input class="cbox" onclick="if(this.checked){document.getElementById('school').style.display ='inline'}else{document.getElementById('school').style.display ='none'}" type="checkbox" name="type[]" value="School" checked/><br>';
Obviously, if I use speech marks to enclose the echo, it would fall apart in the onlick event. How can I avoid this?
要在php中转义字符,请使用\\,如下所示:
echo '<input class="cbox" onclick="if(this.checked){document.getElementById(\'school\').style.display =\'inline\'}else{document.getElementById(\'school\').style.display =\'none\'}" type="checkbox" name="type[]" value="School" checked/><br>';
You need to escape your quotes with \\"
Like this:
echo "<input class=\"cbox\" onclick=\"if(this.checked){document.getElementById('school').style.display ='inline'}else{document.getElementById('school').style.display ='none'}\" type=\"checkbox\" name=\"type[]\" value=\"School\" checked/><br>";
在'
之前添加斜杠。
echo '<input class="cbox" onclick="if(this.checked){document.getElementById(\'school\').style.display =\'inline\'}else{document.getElementById(\'school\').style.display =\'none\'}" type="checkbox" name="type[]" value="School" checked/><br>';
If you use double-quotes, you can escape any other double-quotes by putting the \\ character before them.
There are some more details at: http://php.net/manual/en/language.types.string.php
NEVER use echo to output HTML.
But always type it as is
?>
<input class="cbox"
onclick="if(this.checked){
document.getElementById('school').style.display='inline'
}else{
document.getElementById('school').style.display ='none'}"
type="checkbox" name="type[]" value="School" checked/><br>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.