Home > Article > Backend Development > How to correctly output JS statements in PHP
A computer program is a series of "instructions" that are "executed" by the computer. In programming languages, these programming instructions are called statements. A JavaScript program is a series of programming statements. JavaScript statements are composed of: values, operators, expressions, keywords, and comments
1. Method:
echo "<script></script>";
2. Example:
<?php $classState=""; if($state==0){ $classState="已下课"; }else{ $classState="正在上课"; } echo "<script type='text/javascript'> function getState(){ var cs = ".$state."; return cs; } </script>"; ?>
3. JS garbled problem occurs:
header("Content-type:text/html;charset:utf-8") <script type="charset:utf-8;"></script>
Keep PHP encoding
is consistent with the browser parsed page encoding
.
Recommended: "php video tutorial" "php tutorial"
The above is the detailed content of How to correctly output JS statements in PHP. For more information, please follow other related articles on the PHP Chinese website!