| Writing Your First php file |
This is a tutorial for how to write your First php file. In this tutorial we will learn about basic of creating php file what extension we going to give it. How we gonna show inside of the file to ensure that our web-server deals with it correctly because php is important web-server package you may need to specify in apache to look out at php files. you can do this in your http.com file which we looked up when we setup out apache installation. Php is server-side so what ever you write in between php tags would be not able to shown by people usually When you create html tags
<html>
<head>
</head>
<body>
</body>
</html>
<head>
</head>
<body>
</body>
</html>
Its seems this way will in php code :-
1
| <?php ?> |
well we can also specify php code in this way
1
| <? ?> <?php ?> |
codes in this way.
In php codes :-
In php codes :-
1
2
3
4
5
| <?php//every things we write will goes here?> |
You can also combine php and html in pages of webserver.
codes :-
1
2
3
4
5
6
7
| <?php//your stuff?><html>//html tags</html> |
and when you want to include php you should start like
1
2
3
| <?php?> |
or
1
2
3
| <?//like that?> |
But i will prefer
1
2
3
| <?php?> |
I have made root directory in my localhost to save file localhost/series/firstfile when we will use this link to open our firstfile screenshot1.
In apache if save file name index.php or index.html it takes as default file whenever we call root directory at localhost it will open index.php bydefault.
Now we create file file.php in series/firstfile it will show you in localhost see screenshot1.Now let see combine php tags and html tags in file and see output
file.php code :-
1
2
3
4
5
6
| <?php?><html></html> |
In this file when we see output screenshot2 let's see output view page source by right click..
screenshot3 you can see people can see out html tags well php is serverside lauguage so can not be seen by people.php codes are interrupted by webserver. php is serverside scripting language. If we save file name index.php we can not see the page which is in screenshot2 Index of/series/firstfile and the list of files in it.because bydefault index.php will open automatically.
Let create index.php in that i am writing simple commands of php like echo , echo is to use for print anything in output of php file.
index.php codes screenshot4:-
index.php codes screenshot4:-
1
2
3
| <?phpecho 'Hello World.';?></pre> |
Path : localhost/series/firstfile/
output screenshot5.
output screenshot5.
Now you see screenshot6 its similar to screenshot5 just path of screenshot5 is localhost/series/firstfile/ just root directory and in screenshot6 you can see file name index.php same. no need towrite file name because its bydefault take file in root directory.only index name is configured in apache any other name you shoulddeclare with root directory in browser.
Read More Extra Tutorials
No comments:
Post a Comment