Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Javascript and PHP [closed]

Tags:

What is the difference between PHP and 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.

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

like image 230
Kraken Avatar asked Jun 16 '11 08:06

Kraken


People also ask

What is the difference between PHP and JavaScript?

Javascript requires an environment for accessing the database. PHP allows easy and direct access to the database. JavaScript is used to create real-time games and applications, mobile applications etc. A PHP program is used to create dynamic pages, send cookies, receive cookies, collect form data, etc.

Which is better PHP or JavaScript?

The comparison between PHP vs JavaScript ends with the score 3 to 5 – JavaScript beats PHP. Both languages are fairly good in terms of community support, extensibility, and apps they are suited to. JavaScript is certainly more efficient in terms of speed and universality.

Are there closures in JavaScript?

In JavaScript, closures are created every time a function is created, at function creation time.

Does PHP have closure?

Basically a closure in PHP is a function that can be created without a specified name - an anonymous function. Here's a closure function created as the second parameter of array_walk() . By specifying the $v parameter as a reference one can modify each value in the original array through the closure function.


1 Answers

What is the differene b/w php and 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.

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.

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).

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.

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).

You can make HTTP requests to ask the server for things (this is called 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).

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 XSS or SQL injection problem).

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.

like image 121
Quentin Avatar answered Sep 20 '22 21:09

Quentin