HTML, PHP and javascript
HTML, PHP and javascript
我是php、html和javaScript的新手。。我仍然不明白这三者之间的联系。所以这听起来可能很傻。
我知道php是一种服务器端语言。但我不太清楚这个事实,因为我们可以在html中使用php代码。。
所以我的问题是,如果我写下以下内容,这个部分将在哪里运行??这段代码是否发送到客户端浏览器并在客户端执行?还是在服务器端执行并将结果上传到客户端?
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
它在服务器上运行,输出的html被发送到客户端,浏览器会显示它。
正如您已经指出的,PHP是在服务器上执行的,因为浏览器根本不理解PHP。
如果用户/浏览器请求您的index.php文件,服务器将执行您的php文件中的所有php语句。
因此,您的PHP脚本将生成以下代码:
<!DOCTYPE html>
<html>
<body>
My first PHP script!
</body>
</html>
这是从PHP文件中生成的HTML代码,然后将其发送回浏览器。
希望这能解决您的问题:)
简单地说,它是一个三层,首先你的PHP代码在服务器上运行,被解释为HTML,然后发送到你设备上的浏览器,浏览器运行Javascript代码(如果有),然后相应地显示页面
服务器上发生了什么:
echo "My first PHP script!";
客户端浏览器上发生了什么
My first PHP Script
此外,任何javascript都将在客户端执行。例如:
alert("Hi")
将被浏览器读取,并生成一个带有"嗨"的弹出窗口。
享受旅程!
以下是学习的好资源:
- https://www.codeschool.com/
- http://www.codecademy.com/
我这边的一些基本内容。
如果您的文件具有.php扩展名,那么您可以在该文件中编写HTML、php、JavaScript/j查询脚本。
但是,如果您的文件具有.html扩展名,那么您只能在该文件中编写html脚本和JavaScript/jQuery。
PHP:服务器端可执行语言。
HTML/JJava/JQuery:客户端可执行脚本。
test.php
<!DOCTYPE html>
<html>
<head>
<script>
//js code
</script>
</head>
<body>
<?php
echo "Write here php code";
?>
My first PHP script!
</body>
</html>
test.html
<!DOCTYPE html>
<html>
<head>
<script>
//js code
</script>
</head>
<body>
You can't write PHP code in this file, can only write HTML and Javascript/jquery.
My first PHP script!
</body>
</html>
- JavaScript and LiveView (TIBCO Live Datamart)
- Javascript and onMouseOver
- javascript and css firefox issue
- geolocation with javascript and ruby on rails
- Javascript and the DOM issues
- Javascript and Java Communication
- Javascript and Knockout
- Javascript and Css: Height does not change
- javascript and Internet Explorer 8
- Javascript and html, UI construction
- Javascript and Lightbox
- javascript and css styling
- JavaScript and URL parameters
- Javascript and singleton pattern
- Javascript and Ajax Calls
- OAuth, javascript and many URI's
- Javascript and AJAX post method
- javascript and web services WSDL
- javascript and webview in android
- Javascript & and | symbols