PHP脚本中的JavaScript [英] JavaScript within the PHP Script

查看:57
本文介绍了PHP脚本中的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用文本编辑器使用javascript创建了以下php脚本,并运行了我使用XAMPP的php文件.但是,当我运行文件时,出现错误.我保存了扩展名为.php的PHP文件.在下面,我正在插入源代码和错误消息,请尝试解决我的问题!

I have created the following php script with javascript using a text editor and to run the php file I used XAMPP. But when I run the file I got an error. I saved the PHP file with the .php extension. At the below I am inserting the source code and the error message please try to solve my problem!

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>PHP With JavasCript</title>
</head>
<body>
    <?php

        $a = 15;
        
        if($a > 10){
            echo "<script type="text/javascript">
            
                    document.write("OK!");            
            
                </script>";
        }
    
    
    ?>
</body>
</html>


Parse error: syntax error, unexpected 'text' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\HND_WEB\PHP\PHP_with_JavaScript.php on line 13

推荐答案

a = 15 ; if(
a = 15; if(


a> 10){ echo " text/javascript " OK! ); </script>"; } ?> < /body > < /html > 解析错误:语法错误,意外的文本"(T_STRING),预期为,"或;"在第13行的C:\ xampp \ htdocs \ HND_WEB \ PHP \ PHP_with_JavaScript.php中
a > 10){ echo "<script type="text/javascript"> document.write("OK!"); </script>"; } ?> </body> </html> Parse error: syntax error, unexpected 'text' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\HND_WEB\PHP\PHP_with_JavaScript.php on line 13


您必须在双引号字符串中的每个双引号之前插入转义符(\).
You have to insert escape character (\) before each double quote that is inside a double-quoted string.
<?php
    


这篇关于PHP脚本中的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆