This example is the example of PHP and JavaScript interaction, PHP in the value assigned to the JS variable, if the PHP variable must have a value to do, even if it is a false branch.
For example, $flags in PHP is true in this example, if JS false statement is written: $title _1.innerhtml = "<?php echo $title;? > "There will be an error because $title is assigned to an array in PHP
Although the flags== in PHP is "false"; $title is a string, the case is $title is an array, and the array is not directly displayed in the string.
Copy Code code as follows:
<?php
$string = "heaven and earth";
$flags = "";
if (STRPBRK ($string, "and")!=false) {
$title = Explode ("and", $string);
$title _1 = $title [0];
$title _2 = $title [1];
$flags = "true";
}
else{
$title = $string;
$flags = "false";
}
?>
->html
Copy Code code as follows:
<meta http-equiv=content-type content= "Text/html;charset=utf-8" >
<title></title>
<script type= "Text/javascript" >
var display = function () {
var flags = "<?php echo $flags;?>";
var $title _1 = document.getElementById ("Title_1");
var $title _2 = document.getElementById ("title_2");
if (flags== "true") {
$title _1.innerhtml = "<?php echo $title [0];? > ";
$title _2.innerhtml = "<?php echo $title [1];? > ";
Return
}
if (flags== "false") {
$title _1.innerhtml = "<?php echo $string;? > ";
Although this is a false branch, logically this $string can be replaced with $title, but although only the real branch of the top, but the compilation of
This bogus branch must also be compiled, so the echo $title is wrong, because $title is an array, only $string;
}
}
</script>
<body onload= "display ()" >
<div id= "Title_1" ></div>
<div id= "title_2" ></div>
</body>