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.

  • 2
    No. You can't do anything on the client side with PHP once the page is loaded. – zneak Oct 22 '11 at 15:25
  • Okay, the reason is, I am a blogger at a company, and have very less (to no) time to cater to programming. –  Oct 22 '11 at 15:25
  • Then you'll want to learn JavaScript since there is probably hardly a reason to modify the blogging engine. – zneak Oct 22 '11 at 15:26
  • Is there an easier JS alternative that enables me do real-time web applications? (just asking) –  Oct 22 '11 at 15:27
  • 2
    As your username says, you are truly a badlearner ;) – Raj Oct 22 '11 at 15:32
  • 1
    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. –  Oct 22 '11 at 15:35
  • 1
    Reloading parts of a page can be done using a HTML ` – mario Oct 22 '11 at 15:41
  • Why not server-side Javascript? [Node.js](http://www.google.com.ng/url?sa=t&rct=j&q=node.js&source=web&cd=1&ved=0CCcQFjAA&url=http://nodejs.org/&ei=PeOiTo6nD4rPsgauzfzwAg&usg=AFQjCNE4Ts3F1ZWcYkLwsfNqE6RHZgUpyg) Wiki : [Node.Js](http://www.google.com.ng/url?sa=t&rct=j&q=node.js&source=web&cd=2&ved=0CDMQFjAB&url=http://en.wikipedia.org/wiki/Nodejs&ei=PeOiTo6nD4rPsgauzfzwAg&usg=AFQjCNFPXzMxDqhrkaKKyyOwPo0P64SDCg) http://stackoverflow.com/questions/2353818/how-do-i-get-started-with-nodejs – Mob Oct 22 '11 at 15:38
  • One short Q: Can it do everything the real Javascript programming language can? For instance, like I mentioned, live (real-time) comments display? –  Oct 22 '11 at 15:42
  • @badlearner I think so. http://stackoverflow.com/tags/node.js/info – Mob Oct 22 '11 at 15:47
  • @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. – vstm Oct 22 '11 at 15:49

6 Answers6

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.

vstm
  • 12,407
  • 1
  • 51
  • 47
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.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
  • 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. –  Oct 22 '11 at 15:33
  • 1
    you need a bit of JS for that, with jquery it's really simple. – Karoly Horvath Oct 22 '11 at 16:11
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.

BudwiseЯ
  • 1,846
  • 2
  • 16
  • 28
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.

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.

Rafe Kettler
  • 75,757
  • 21
  • 156
  • 151
  • 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. –  Oct 22 '11 at 15:34
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.

millimoose
  • 39,073
  • 9
  • 82
  • 134