Javascript 和 PHP 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6369313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:27:25  来源:igfitidea点击:

Difference between Javascript and PHP

phpjavascript

提问by Kraken

What is the difference between PHP and Javascript?

PHP 和 Javascript 有什么区别?

I know one is server side scripting and the other is browser side. but what I'm asking is that using Javascript, can I display alert messages,which i can simply do with PHP also,without using any function, or using some if-else combination.

我知道一个是服务器端脚本,另一个是浏览器端。但我要问的是,使用 Javascript,我可以显示警报消息吗,我也可以简单地用 PHP 来做,而不使用任何函数,或者使用一些 if-else 组合。

So are PHP and Javascript are exclusive, like if i use one then the other one should not be used, or?

那么 PHP 和 Javascript 是排他性的,比如如果我使用一个,那么另一个就不应该使用,或者?

回答by Quentin

What is the differene b/w php and javascript

b/w php 和 javascript 的区别是什么

Roughly akin to the difference between English and German. They can express largely the same things, but do so in different ways, and you'll have more luck using English in Germany then German in England.

大致类似于英语和德语之间的区别。他们可以表达大致相同的东西,但以不同的方式表达,在德国使用英语会比在英国使用德语更幸运。

i know one is server side scripting and the other is browser side

我知道一个是服务器端脚本,另一个是浏览器端

Not really.

并不真地。

PHP is a programming language. It is often used for server side programming, but has uses in general programming too.

PHP 是一种编程语言。它通常用于服务器端编程,但也用于一般编程。

JavaScript is a programming language. It is the only language that has a decent level of native support for running in a browser. It has a wide variety of server side implementations (including Node and ASP). It is one of the languages you can use with the Windows Scripting Host. etc.

JavaScript 是一种编程语言。它是唯一一种对在浏览器中运行具有良好原生支持的语言。它有各种各样的服务器端实现(包括 Node 和 ASP)。它是您可以与 Windows Scripting Host 一起使用的语言之一。等等。

There are plenty of other languages that can be used for server side web programming too (C# is popular in ASP.NET, I'm rather fond of Perl, there are quite a lot of proponents of Python and Ruby, Java has a strong following, and so on).

还有很多其他语言也可以用于服务器端 Web 编程(C# 在 ASP.NET 中很流行,我比较喜欢 Perl,Python 和 Ruby 有很多支持者,Java 有很多追随者, 等等)。

That said. El Cheapo hosting which supports PHP is a lot more common than El Cheap hosting which supports other things. Leaving language partisanship aside, the primary disadvantage with it is that El Cheapo hosting is has the You Gets What You Pay For rule.

那说。支持 PHP 的廉价主机比支持其他东西的廉价主机要常见得多。撇开语言党派之争不谈,它的主要缺点是 Elchepo 托管是一分钱一分货规则。

If we take your question to be about the difference between server side and client side programming though…

如果我们认为您的问题是关于服务器端和客户端编程之间的区别……

but what m asking is that using client side programming i can display alert messages

但是我要问的是使用客户端编程我可以显示警报消息

With client side programming you can manipulate things in the browser without going back to the server. e.g. you can add elements to the document to display a message.

通过客户端编程,您可以在浏览器中操作内容,而无需返回服务器。例如,您可以向文档添加元素以显示消息。

You also have access to APIs provided by the browser, such as the alert()method which will display a message box that isn't an intrinsic part of the document and Local Storage (which lets you store data in the browser which only that browser will have access to).

您还可以访问浏览器提供的 API,例如alert()将显示不是文档和本地存储的固有部分的消息框的方法(它允许您将数据存储在浏览器中,只有该浏览器才能访问)到)。

You can make HTTP requests to ask the server for things (this is called Ajax).

您可以发出 HTTP 请求来向服务器询问事物(这称为 Ajax)。

which i can simply do with server side programming also,without using any function

我也可以简单地使用服务器端编程来完成,而无需使用任何函数

With server side programming, you can modify the document you are sending to the client, but only at load time.

通过服务器端编程,您可以修改发送给客户端的文档,但只能在加载时进行。

You can access shared resources (such as the contents of a database that lives on the server).

您可以访问共享资源(例如位于服务器上的数据库的内容)。

You don't have access to things like the alert()method. (Although you can generate program code (usually in JS) that will run client side and will have access to those methods).

您无权访问alert()方法之类的东西。(尽管您可以生成将运行客户端并可以访问这些方法的程序代码(通常在 JS 中)。

so does server side and client side programming are exclusive ,like if i use one then the other one should not be used,or ??

那么服务器端和客户端编程是否是互斥的,比如如果我使用一个,那么另一个就不应该使用,或者??

In general, any essential functionality should be handled with server side programming. Build on things that work. Client side programming can break, either because you depend on a feature that isn't available in the browser the user is using, because a script fails to load, because the user happens to have JavaScript turned off, or because the user is trying something malicious (such as passing data to the server that could cause an XSSor SQL injectionproblem).

通常,任何基本功能都应该通过服务器端编程来处理。建立在有用的东西上。客户端编程可能会中断,因为您依赖的功能在用户使用的浏览器中不可用,因为脚本无法加载,因为用户碰巧关闭了 JavaScript,或者因为用户正在尝试某些东西恶意(例如将数据传递到可能导致XSSSQL 注入问题的服务器)。

Client side programming, on the other hand, can be used to make things more convenient for the user. You can add animation to indicate that something is happening, check data before it is submitted to the server (saving the time of a round trip), update part of a page periodically, and so on.

另一方面,客户端编程可用于使用户更方便。您可以添加动画来指示正在发生的事情、在将数据提交到服务器之前检查数据(节省往返时间)、定期更新页面的一部分等等。

回答by Gabriel Spiteri

It mostly depends on what the situation / functionality desired involves.

这主要取决于所需的情况/功能所涉及的内容。

Definitely not exclusive because you can't search a server side database with javascript. On the other hand javascript can make the user browsing experience much more interactive and user friendly.

绝对不是排他性的,因为您无法使用 javascript 搜索服务器端数据库。另一方面,javascript 可以使用户浏览体验更具交互性和用户友好性。

I would say that javascript and php can work in total harmony making your website much more fun to use.

我想说 javascript 和 php 可以完全和谐地工作,使您的网站使用起来更有趣。

It's just a question of understanding when and how to use each one :)

这只是一个理解何时以及如何使用每一个的问题:)

HTH

HTH