NOT PHP vs JS Comparison: Can I do anything in PHP that can be done with JS?
Asked Answered
F

6

1

I've now got some very good understanding of (X)HTML and CSS, and plan to move on. My next choices are PHP and JS (and don't know if I'll ever end up learning one of them, but I would love to).

So, I need to choose one of them. I have learnt that PHP is server-side programming and JavaScript is client-side programming, and I am NOT asking you to compare the two of them for me. What I would like to know is, can I do anything (or most of) in PHP that can be done with JS? (or put it this way, can do everything people use JS for, on the server-side with PHP?)

Instances include, using PHP instead of JS in web themes, real-time content display (as in live blogging, live comments etc), effects etc.

This might seem dumb, and there's definitely a reason why people use JS in all the above instances, but since I cannot (really) learn the two of them, thought I should ask for some advise here.

EDIT: Would it be possible to reload only a part of a web page (not the entire web page) every few seconds with PHP? That should be good enough for the real-time application that I am planning.

Finned answered 22/10, 2011 at 15:23 Comment(11)
No. You can't do anything on the client side with PHP once the page is loaded.Cheney
Okay, the reason is, I am a blogger at a company, and have very less (to no) time to cater to programming.Finned
Then you'll want to learn JavaScript since there is probably hardly a reason to modify the blogging engine.Cheney
Is there an easier JS alternative that enables me do real-time web applications? (just asking)Finned
As your username says, you are truly a badlearner ;)Veridical
But I am definitely trying to be otherwise, if only I had time. :( I just love to be able to program something useful to me.Finned
Why not server-side Javascript? Node.js Wiki : Node.Js #2354318Woodham
Reloading parts of a page can be done using a HTML <iframe> and a meta refresh tag. But that's not overly pretty.Maximalist
One short Q: Can it do everything the real Javascript programming language can? For instance, like I mentioned, live (real-time) comments display?Finned
@badlearner I think so. stackoverflow.com/tags/node.js/infoWoodham
@badlearner: Well there is a Javascript-Interpreter integrated in every major browser. This is the "client"-side. Then there is the "server" or "backend" which does all the heavy processing / data storage. Node.js is just a Javascript-Interpreter which enables you to create server-side applications. In fact Nodes.js is based on the "V8"-engine which is also built into the Chrome browser.Ence
F
1

For nice user experience (dynamic menu, ajax, effects, ... ) you need client-side programming and for dynamic content you (almost always) need server-side programming.

In short, you need both.

Fording answered 22/10, 2011 at 15:26 Comment(2)
would it be possible to reload only a part of a web page (not the entire web page) every few seconds with PHP? That should be good enough for the real-time application that I am planning.Finned
you need a bit of JS for that, with jquery it's really simple.Fording
E
2

If you absolutely don't want to learn both, then learn Javascript. There are possibilities to implement a Javascript-based backend with node.js.

I advise you to at least try PHP since it is widely used - maybe even at your company.

Ence answered 22/10, 2011 at 15:32 Comment(0)
F
1

For nice user experience (dynamic menu, ajax, effects, ... ) you need client-side programming and for dynamic content you (almost always) need server-side programming.

In short, you need both.

Fording answered 22/10, 2011 at 15:26 Comment(2)
would it be possible to reload only a part of a web page (not the entire web page) every few seconds with PHP? That should be good enough for the real-time application that I am planning.Finned
you need a bit of JS for that, with jquery it's really simple.Fording
D
1

PHP and JavaScript cannot really be compared in the way you're asking... Both are powerful in what they've ment for and they have a very similar syntax. If you can't absolutely study more than one of them, learn PHP in my opinion. I coded with PHP for almost 10 years before really getting into JS. I would say PHP is the food and JS is the spice.

In order to create AJAX web apps Javascript AND a server-side language is required.

Disclosure answered 22/10, 2011 at 15:39 Comment(0)
B
0

No, you can't. PHP only works on the server side. Once you've delivered content to the client, PHP can't do anything until the page reloads or the user loads a new page. If you want to do anything client-side in between, you need JavaScript (this includes loading content in real-time, doing a lot of modern UI stuff, etc).

Either learn both PHP and JS or use a blogging CMS and use a minimal amount of both.

Berrios answered 22/10, 2011 at 15:27 Comment(1)
would it be possible to reload only a part of a web page (not the entire web page) every few seconds with PHP? That should be good enough for the real-time application that I am planning.Finned
T
0

If you put enough effort into it, you can do almost anything server-side using lots and lots of page reloads. You can also generate arbitrarily complex dynamic content using Javascript.

But it's a lot easier to do minor changes to a page's content from Javascript, it's only possible to do animations and effects from Javascript. It's also much easier to directly access the database from server-side code – there might be pure-javascript drivers for SQL databases, and you could use a NoSQL databases that's accessed using web services, but both are relatively uncommon techniques.

Tradeswoman answered 22/10, 2011 at 15:31 Comment(0)
V
0

I have a thought regarding your original question/situation. I know this is about four years tardy, but I thought I should throw in my two cents for people who are looking back on this conversation as a reference from Google like I am. In your situation, because you are a blogger who is trying to save time when it comes to programming, I would recommend looking into WordPress (the .org version, not the .com). It is a sort of marriage of WYSIWYG blogging/website creation and programming. It takes care a lot of the back end stuff (including Javascript, PHP, and more), but also leaves it open for you to edit if you so desire. You probably could get away with using Wordpress as a total non-coder, but with HTML and CSS, you're already off to a great start. WordPress is super simple to learn and amazingly powerful. If you do take this route, I would suggest learning PHP as an asset because that is the language that WordPress runs off of. If you know PHP and are using WordPress, you have vast potential, not to mention that speedy blogging is a snap. If you don't feel the need to have whipped everything up from scratch and want to work faster, give WP & PHP a try. They'll take you a long ways.

Versieversification answered 6/5, 2015 at 3:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.