Python or PHP - which one to choose

Hello,

I hope it’s ok if I ask this question. I’d like to be able to edit a single HTML code to change multiple pages e.g. the footer, the header, the navigation, or the sidebar. Do I use PHP or Python? Let me be honest with you. All I know is that these languages are server-side languages. I also did learn that Python is easier to learn than PHP and is more powerful. I plan to enroll in a course but not sure which language to choose to accomplish this aim. I know I can use WordPress or a similar CMS but I don’t wish to depend on these for my specific project. I’ll appreciate your input. Thanks

Hi @ME20!

If your goal is to have a reusable navbar, footer, header, etc across all pages than you can actually accomplish this with javascript. That is what I did for my project I am currently working on.

I mean PHP works to but if you already know javascript I would just do that.

1 Like

Hi jwilkins.oboe!

Thanks for your input. I haven’t learned JavaScript yet. Shall I take Python, PHP or JavaScript?

Since you are interested in web development Javascript would be the way to go. I would continue through the FCC curriculum to the javascript section and that will give you the tools necessary to build what you want.

2 Likes

This is very interesting to know. I’m thinking of enrolling in a video course to learn JavaScript. So if I understand you correctly, let’s say I want to change “contact us” in the navigation menu to “Visitors”. Instead of having to change it on every page, I’ll harness the power of JavaScript to make the change on one page to make it affect all the other pages similar in concept to when you change the color of the text in CSS and it will affect the the text color on all the pages. JavaScript will do the same to the text i.e if I change “contact us” to "Visitors"on one page the change will affect all the other pages. Am I correct?

somewhat yes, but instead you would have a JavaScript file, where you write the script to create that html element, and then you can import that in all the pages you want it, and then you just make changes to the first JavaScript file if you want to change something

something similar works for php, only that for php you need to have a back-end, with JavaScript you can do that without a backend (server-side) logic

I don’t know with Python, other than you would also need server-side logic, and also a Python framework, like Django

2 Likes

@ilenia summed it up perfectly. I think if you go through the the FCC curriculum it give you want you need. You are free to do the video course as well but FCC will teach you the skills too.

1 Like

Many thanks to both of you for the input and the insight. So basically, if I’m looking to create a newspaper let say where I want to change the text in the navigation menu or in the footer, or in some defined section, I can rely on JavaScript instead of WordPress.

Can you please provide with the link to the tutorial you mention? Thanks

You can find the freecodecamp curriculum at freecodecamp.org/learn

Hi @ME20, I don’t want to create any more confusion, but to me looks like you are after what’s called a template engine.

I think you are after a functionality where you write “pseudo” html that gets populated with data, for example:

 <h1>{{ pageTitle }}</h1>

Then if somehow I instruct that pageTitle should be “Hello World!”
My final html would be

 <h1>Hello World!</h1>

If this is the case you are in luck, every programming languages somehow has a templating system to help you with that :slight_smile:
There are even amazing tools that lets you create full complete website with it.

My suggestion than would be to pick a language that you like (or feel has more/better resources to learn) and stick with it: any tech you’ll choose will do for your idea :sparkles:

Hope it helps.

2 Likes

Hi Marmiz, Thanks for your input. Yes, this what I’m looking to achieve. However, which language shall I choose? I don’t know anything about PHP, JavaScript or Python. Which one is easier to learn? Do you’ve a refence on the template engine?

Whether you use a template engine, php or just plain old vanilla javascript all of these options will do the exact same thing. I had asked the same question months ago and found out that there are multiple options.

If it is your first programming language, there will be a learning curve for any of them but again there is no wrong option. Just get started. Don’t get hung up on picking the wrong language. Who cares about the nuances and pros and cons to a language. Learn the basics first. A string, a variable, a function, all do the same thing they just look different. So don’t get trapped in the paralysis of the analysis.

I would suggest picking a learning format that suits your learning style and start learning. Once you start learning you will see how easy it is to create what you are talking about.

Happy coding!

Many thanks, Jessica. :+1:

Just for your consideration some facts

  • PHP - 79%
  • Python - 1.4%
  • JavaScript - 1.1%

Data from 18 November 2020

1 Like

Hello Chris, Thanks for the insight. I guess I should learn how to use PHP since it has a very high market share. I’ve also learned that PHP forms the heart of WordPress.

That usage data is only for server side (or back end) programming. There is far more to web development than server side programming. I’d still recommend JavaScript, especially since it looks like you were talking about front end development (at least to me, but what do I know, I’m a C dev :smiley: ).

Yes, Wordpress is built on PHP, as most of the websites as we can see on those stats.

If you want to become backend web developer I’d suggest to learn PHP. It was written as a tool to embed dynamic data directly into HTML and it’s still true even nowadays. You can still use it or treat it as direct template engine. You can embed it directly into HTML like this (following a previous example):

Short version

<h1><?= $pageTitle ?></h1>

or with full “<?php” tag

<h1><?php echo $pageTitle; ?></h1>

Might look scary at first glimpse but I think in general it might be much easier to learn and understand the basics.

As web developer you would still need to learn HTML, CSS, JavaScript (on the frontend side - in a browser) and some basics of SQL and databases.

Javascript become to be used as backend language just in a few recent years and I think technicality this might be much more complicated to approach then old fashion PHP because of single-thread asynchronous nature of JS backend.

There is a good article in here https://www.freecodecamp.org/news/php-vs-javascript-which-technology-will-suit-your-business-better/ which confirms my point that PHP is easier to learn. It also mentions that it’s important what do you want to build, in your case, and thousands other cases involving web services and sites, PHP would be a much better choice .

Backend JS is more suitable only for things like native JS apps (like Flash some years ago) or tools like chat communicators on the website, IMHO.

Python become popular recently as it’s used mainly to build a constrains and environments for AI algorithms to be able to learn and educate themselves.

1 Like

Considering something like 35% of all websites are using Wordpress it’s no wonder that the statistics would look like that. However, I would like to point out that going by that logic alone you should also be using jQuery (statistics of JavaScript libraries) and not React, Vue, or Angular. Which is most definitely not true at all.

I’m not saying you shouldn’t use or learn PHP. In fact, knowing PHP because it is so widely used is likely good knowledge to have in your toolbox as a dev no matter what.

But it sounds like you have not started to learn to program at all yet so personally, I would suggest you also focus on the learning experience and pick a language that is easy to use (like JS which runs in the browser) and lets you focus on the core of programming and not just looking at the end goal (i.e. you want to do X so you pick Y language). Most core skills learned in one language are transferable to other languages.

Personally, I would go with JS, and then when you have the basics down learn something like React, or Vue, etc. You do not need a back-end for the site to be dynamic, you can do dynamic sites using client-side only code.

That’s not to say you should limit yourself to one thing, you can still learn PHP as well. But I’m not sure I would suggest it as your first language to learn to program in, but I’m probably biased.

2 Likes

My thanks to all of your for the input and the insight. I’ve recently learned HTML and CSS and can build responsive pages using HTML5, CSS3, (I write media queries to make a page responsive). I’d like to learn how to create a website for an imaginary newspaper. I realize that I can build pages using the in-built editor tools in WordPress but I’m looking for an alternative. What are your thoughts on this?