So in last tutorial you learn how to install a local server on your computer and then this tutorial you're actually going to start writing some code in PHP so as you guys can see before you get started you should have their patch a magical service running inside XAMPP control panel if you don't have this running you won't actually see the code you're going to write in this article.
So what you're going to do now after we have this running you're going to go to the browser. You're going to type localhost inside our URL and hit enter. Now you guys are probably just going to have one folder from last lesson just make sure you open up the folder you created in the last lesson. So you are going to open up the one you called PHP lessons.
Now in here you guys will notice you do actually get a directory the reason we get a director right now is because you don't actually have a starting page for your website.
Now when it comes to starting pages if you do actually open up your code editor and create a new document if you were to save this new document as index.HTML it would actually recognize it as a starting page. You can also write index.php and you'll also you know recognize this as your starting page. So it doesn't really matter if you use index.HTML index.PHP you will automatically see this one as a starting page no matter the extension. So after you say this as index .PHP inside your directory of course inside your root folder inside htdocs' then you can actually start writing code.
Now the thing about PHP documents is even though you have the PHP extension you can still write HTML and JavaScript code in here. So if you were to open up you know just a very basic HTML5 layout this is just the starting layout for a new website you have the HTML tags up there. You also have the doctype so you have the HTML opening and closing tags you have the body tags you have the head tags and just a small title tag and there with two meta tags so this is a very basic you know starting layout for a website inside HTML. Now in order to write PHP code you need to use something called PHP opening closing tags. Now the way you write those is by saying lesser than question mark PHP which by the way is the opening tag if you want to close it again you're right question mark greater than so everything that goes in between these tags are going to be PHP code. You should mention that you have to write these PHP tags if you want to write PHP code otherwise it's not going to recognize it as PHP code.
So in between these tags you can actually start writing something and the first thing is how to print something on the screen. Now in the last lesson you did actually seen an example of how to print something so we can actually write echo inside our PHP tags which is essentially that you echo something out on the screen. You actually write something on the screen so you are going to say echo space court agent marks and then you need to make sure we actually end the line of code by writing semicolon at the end kind of the same way as you do in CSS when do you want to end off a piece of code. So in between the quotation marks you can actually write something so this time you'll say "hi there" and do notice that hi spelled correctly this time and if you were to save this and refresh it inside your browser you guys will notice that when you refresh it does actually see oh you got a index document and it's just automatically going to take you to it.
As you guys can see right there. So right now you have a piece of text this is "hi there" now if you want to write something else you can also use a statement or like a function called print. Now print does the same thing as echo does there's a couple of differences but right now there's not really any important differences other than that echo is faster loaded inside your browser. So if you want to print some text and you want to be fast echo is faster even though it's very very you know little amount to make it faster. So you can actually go down to the print and write quotation marks again and you can actually write you name. So you'll say hello there you hide Daniel and you need to make sure you end up with a semicolon of course if it were to save this refresh your browser you guys will notice you have some text going on.
Now you don't have a space in between here and that's because you do actually need to add a space after there and then you'll actually create the spatial mean but these are two ways you can actually print out stuff inside a browser.
So if you go into your echo and say 12 let's say something simple 10 plus 5 and you save it. Refresh your browser you guys will notice it as 15 because 10 plus 5 is 15. So you can also do very basic math statements which is going to become useful later on if you want to do you know functions or if you want to make statements or if you want to you know just do something a little bit more complicated. You will have to do a little bit of math later on because PHP is a a technical question programming language so you will probably be doing some math later on. Now these are some of the basics ways you can actually print out stuff and that's what you are going to focus on in this article. In the next article you're going to learn about something called variables and variables are something you're going to use quite often in PHP.

No comments:
Post a Comment