Basic File Syntax

4 minutes
Share the link to this page
Copied
  Completed
Learn about the basic format of a PHP file and how to utilize basic features.

Transcript

Hello, in this PHP video, I am going to cover just the basic file syntax. So if you watch this certain video, I basically create this index dot php file. And so yeah, or PHP files need to have the extension dot php and to start coding in PHP so let me just delete this, you need to put what are called canonical PHP tags, you can call them PHP tags, they stopped by pouring, you know, less than, or you know, opening angle bracket question mark, PHP, and then you close this off by question mark, great thing in order to put PHP anything that is between this is going to be paused by you know, the, you know, the the parsing engine, as PHP is coming recognize with PHP so if I was to put you know, that echo against like I say echo toy Monday, which is in terms of when I'm recording it and know what day it is, for when you're watching it and if I say Go to the web browser refresh.

As you can see, he says, Hi, it's Monday. And you know what I'm going to zoom in a bit. to, to, I should be in the back, no is the microphone into the Hi, it's Monday, if I was to put this outside of the tags that are below above your demonstrate second one, we're looking at syntax highlighting for PHP, because it's outside of the PHP tags on, you know, look what happens if I refresh this, it literally puts out exactly what I put. So anything outside of any PHP tags in a PHP file is considered HTML. So here, I could actually put HTML code, I could literally put the HTML tag, I could put you know, the doctype as well. doctype HTML, and obviously, in here, you would put your head your upper body organs can go straight to the body part and we could lift a clip This here operate, you know, between football.

And now if I say that, boom, there we go. It is bold, and we are using HTML. So that's how you would use HD out. If you want to use PHP inside the pasty mom, maybe you wanted to do, maybe you know, you calculated something and you wanted to print something out. Yeah, you could do something along the lines of this Echo, let's say for this echo file, so it's going to echo the number five, but what you'll see is we'll just get five. And if we inspect the element, let's close this down.

I didn't see five of them printed out into the beat. So that's how you combine HTML and PHP code. So there's a normal thing that you can do. So instead of using these tags, you can use what are called the short open tags and the short tags are essential. They're almost the same. Instead of PHP, you don't put that there, I usually prefer to put that.

So you know, at a quick glance from looking at some code, and maybe don't look at the file extension of switching between different, you know, files of different languages, I can easily identify it because it's PHP. And this sort of format can be used for the stuff I was asked the reason I prefer the other one, but as you can see, it will just work just fine. So if I put Hello here, there we go, we get Hello. And really, that's it for the basic file syntax. Obviously, over the rest of this series will cover all of the other different features that you will need. Apart from that there's really not much else that you need to know just in terms of basic fundamentals.

Okay, one other thing, similar to c++, if you come from a c++ background or even a JavaScript background Java background, you'll notice the semicolons. So the way you The you know, the interpreter knows that this has, you know, this the end of the line is by printing semi colon. Whereas in languages like Python, for example, which are, you know, very popular nowadays, the way that interpreter would know, they see the end of the line is by having literally a whole nother line. But with this, you need to put semicolon, I prefer semicolon roof, it generally just worked very tough to worry about indentation or anything like that. You should obviously always indent your code for, you know, good practice, but it's not required for it to run. So that's it.

Any questions? You know, as usual, feel free to drop me a message or code will be provided on the GitHub page. And yeah, I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.