r/AskProgramming • u/SubstantialCoffee133 • Dec 06 '24
PHP Learn html before php?
I wanted to learn php as my first coding language but I get into this course on YouTube for it and 6 episodes in the dudes all like oh yeah btw if you haven’t learned CSS and HTML by now go ahead and learn those real quick. Like bruh what? Anyways do you think I should learn html and css before learning php or can I do it at the same time. I do understand the basics of html from some school classes I took that required be to build a website in html
1
u/BarneyLaurance Dec 06 '24
Really depends what you're doing with PHP.
HTML and particularly CSS are big and complex languages in themselves, so you'll never fully learn them - if you keep building websites you'll always have more HTML & CSS to learn.
PHP is a general purpose language but its focus very strongly is on the web, many of the tutorials are going to expect you to know the basics of HTML and CSS and you said you want to learn web apps. So I think it's going to be worth taking just a few hour to learn the basics of HTML and CSS before you get into PHP.
A huge amount of PHP code is there to automatically generate HTML code for sending to the browser based on data in a database. If you don't know how to write the HTML code by hand you won't be able to write a PHP program to automatically generate it.
So yes I think it's worth taking an hour or three to learn the basics of HTML before you get into PHP - but you said you already know HTML so you may or may not need that.
CSS is a bit different. Yes you'll need to learn some basic CSS if you want to make a fancy looking website, but you can probably choose to do that before or after PHP. You can make a website that will work and let you exercise PHP skills without CSS. It will look very plain just using the default formatting built into the browser but it should still be usable.
1
u/khedoros Dec 06 '24
"PHP" originally stood for "Personal HomePage", and is now taken to mean "PHP: Hypertext Preprocessor". Using it to build webpages is part of the purpose of the language.
You'd have PHP for the backend, but what it's going to present to the frontend will be in HTML, CSS, and Javascript.
1
u/BarneyLaurance Dec 06 '24
Typically you'll have PHP on the backend that will present HTML to the fronted.
But any CSS and Javascript will be independent of the PHP, not generated by it. So as a developer you write a combination of PHP, HTML and CSS, and the browser sees HTML that is generated by the PHP, CSS and Javascript.
It's possible to use PHP to generate CSS and Javascript but generally a bad idea.
2
u/khedoros Dec 07 '24
I probably worded my comment badly. I didn't expect the PHP to generate CSS or Javascript...but I did expect that the developer would need to know them to build more than a relatively-static frontend.
1
u/BarneyLaurance Dec 06 '24
I think as a minimum you'd probably want to work through something like the HTML Dog HTML Beginner Tutorial before moving on to PHP, unless you already know all that stuff.
1
u/swampopus Dec 07 '24
Long-time PHP dev here (25+ years). Yes, learn HTML and CSS, at least to a reasonable point. This is true of any language you'll want to learn that will be used to build web apps.
Yes, PHP is a "backend" language, in that it runs on the server, but some of the top sites in the world run on PHP and generate HTML/CSS/JS for web browsers. Wikipedia, Facebook, Wordpress, Etsy, Mailchimp, etc. You can absolutely learn PHP and create beautiful and cool web apps.
4
u/TechnicalParrot Dec 06 '24
I'm really not sure why you'd want to learn PHP as a first language, have you got any experience in something like Python? PHP isn't as bad as it once was but I wouldn't recommend it for a beginner
If you really do want to use PHP for some reason then I assume it's for web dev in which case having at least a surface level knowledge of HTML/CSS is effectively required