PHP best tutorial for beginners: In the previous lesson, php best tutorial for beginners level to advance part-2, we have covered how to make your PC a local server for work.
Today i am going to write about how to write code, where you have to write your code. So lets start today’s lesson guys.
PHP Code Writing:
If you install XAMPP in C drive in your PC, then here you will find a folder, htdocs. You have to store your web content here.
Main directory of all www Document is “C:\xampp\htdocs” ( But if you install it another folder like- D drive then it will be “D:\xampp\htdocs” ).
Now if this folder contain a file- “index.php” then you can access it in this way- write in your address bar- http://localhost/index.php
Now we are going to write our code, but before that here is a question where you can write your code? Yu can use NOTEPAD++, Net Beans, Dreamweaver, Brackets etc. This code editor is called IDE ( Integrated Development Environment )
You will write your code where you can feel better actually. It totally depends on you.
Now, We are starting to write some basic syntyax of PHP.
PHP best tutorial for beginners- PHP Basic Syntax:
When you are working with PHP, you have to save the file with .php extension. If you save with .html extension it will not work.
- Every part of PHP code start with <?php and end with ?>Every instruction (code line) will end with semicolon.
Now open your IDE and write a simple code like that-
<?php echo"Hello World!!! This is my first php code"; ?>
Now save this with index.php and save in htdocs folder. Then go to browser and write in the address bar- http://localhost/index.php and then press enter.
You can see your output.There is some short way to write php code. See this-
<?= "Hello World!! This is my first web php code";?>
Which means here you can write <??> instead of <?php?>, and you can also write = instead of echo. Code will work
Here is some example:
<script language="php"> echo "This is my first php code"; </script>
Beside this you can write ASP style but this is now exploded.
- First type is the best practice in this above code.
To use short tag you have to enable short_open_tag in php.ini file.