What is PHP?
PHP was developed by Rasmus Lerdorf in 1994.PHP is a recursive acronym for PHP: Hypertext Preprocessor. It is widely used open source scripting language embedded into HTML that is suitable in developing dynamic web pages. It is compatible with most DBMS such as MySQL, Oracle, Sybase, etc.
PHP is a server side scripting language. Therefore, php scripts runs/executed on the server. You will be needing a software such as WAMP (Windows, Apache, MySQL, PHP), XAMPP, LAMP for Linux operating System and MAMP for Mac OS. If you are going to upload it online, you will be needing a server that runs apache, php, mysql such as Apache or IIS.
You can download the latest version of WAMP Server on their official website. Or if you wish to use XAMPP which what I prefer, you can download it here.
Install it in your windows pc or if your using Linux then you install LAMP. To run your PHP, you need to look for XAMPP control panel. Make sure to install it first. Next, a form will display that looks like in the image below. Click on the start button that corresponds to Apache.
How PHP really works using this software? Let's take the following code as an example.
<!DOCTYPE html> <html> <head> <title>Simple PHP Script</title> </head> <body> <?php echo "Hello World!";?> </body> </html>
Your php script starts with the PHP start tag <?php and ends with a php end tag ?>.
The code is being executed on the server and generating an html code back to the users web browser. The users will see a running script but will not be able to see the underlying php script.
A sample visual for you to easily understand. This is your php script on the server.
This is how the code looks like after passing the server.
And this is how it looks like in the user's browser.
Where to save your files in XAMPP?
You can create your php script in any text editor. In my case, I used the Notepad++. Save your file with a php file extension. Example sample.php and save it to the directory
C:\xampp\htdocs\yourfoldername
For the WAMP,
C:\wampp\www\yourfoldername
Or you can visit one of my post related to XAMPP tutorial.
Displaying Output
PHP uses the echo() statement to display outputs like in the above example. Enclosed string with double quotation to display string values.
Common uses of PHP
- Perform system functions: create, open, read from, write to, and close files on your system; execute system commands; create directories; and modify permissions.
- Gather data from forms: save the data to a file, send data via e-mail, and return manipulated data to the user.
- Access databases and generate content on the fly, or create a Web interface for adding, deleting, and modifying elements within your database.
- Set cookies and access cookie variables.
- Start sessions and use session variables and objects.
- Restrict access to sections of your Web site.
- Create images on the fly.
- Encrypt data.
PHP Comments
Comments are used to document your codes in php or to test some part of the code for debugging purposes. Comments are being ignored by the parsing engine and are not executed.
There are three (3) type of comments, // and # for single line comment, and /* */ for multi line comment.
//This is a comment.
#This is a comment.
/*
This is a multi
line comment.
*/
PHP Variables
PHP variables are used to store values such as string, numbers and arrays. All variables in php starts with a $ sign. The following are the naming conventions in creating variables in php.
1. It must start with a letter or an underscore ( _ ).
Example: $first, $_last, $var12. It can only contain alphanumeric characters and underscore. (a-z, A-Z, 0-9, _).
Example: $num1, $first_name, $_num13. It should not contain spaces. If it is more than one (1) word, separate it with an ( _ ) underscore such as $first_name or with capitalization $firstName.
4. It should be descriptive yet short.
5. It is case sensitive. Meaning, $a is not equal with $A. ($a<>$A)
Declaring Variables
<?php $text="Hello World!";
echo $text; ?>
The script above will display Hello World! in your browser. If values are numbers, do not enclosed it with double quotation ("").
Example:
<?php $num=10;
$pie=3.1416;
echo $num;
echo $pie; ?>
Code Cohabitation
Code cohabitation exist when you want to put html tags inside your php script. Since you cannot directly put html tags in php, you need to do echo the html tag and put it inside the double quotation ("") like in the below example.
<?php $num=10;
$pie=3.1416;
echo $num;
echo "<br>";
echo $pie; ?>
<?php $text="Hello World!";echo "<h1>$text</h1>";?>
Note: Use double quotation "" if you want to display the actual value of variables. Use single '' quote to display the literal name of the variable.
String Concatenation
There will be cases wherein you need to combine two or more string values together. To achieved this, you need to use the concatenation operator which is the period ( . ).
Example:
<?php $text1="Hello";$text2="World";echo $text1." ".$text2;?>The purpose of the " " is to put a space in between Hello World. Its like Hello + space + World.
Watch out for more articles related to programming and even systems administration. Please do hit the like button on the right sidebar of this page.
Thanks for your informative post!!! After completing my graduation, I am confused whether to choose web design as my career. Your article helped me to make a right choice. PHP Training in Chennai
ReplyDeleteNice post..thank you for sharing..keep on updating...
ReplyDeleteBest cloud Computing Training Institute in Chennai | Best cloud Computing Training Institute in Velachery
Very useful article.Some valuable tips on how to open URL in Google Chrome Help browser.Waiting for new updates.
ReplyDeleteBE/B.Tech Project Center in Chennai | BE/B.Tech Project Center in Velachery
I found a lot of interesting information here. really good blog, Keep Updating...
ReplyDeleteSummer Camp for Computer Science in Velachery | Summer classes for Computer Science in Chennai | Summer courses for Computer Science in Taramani
It's very nice blog, thanks for the sharing the information
ReplyDeleteExcellent Vacation Courses in Chennai | Good Summer Course in Guindy
Good post..Keep updating..
ReplyDeleteSummer Courses in Chennai | Summer Courses in Velachery
ReplyDeleteThank you so much for sharing this worth able content with us. The concept taken here will be useful for my future programs and i will surely implement them in my study. Keep blogging article like this.
Php course in chennai
Thanks for sharing this information and keep updating us. This information is very useful to me.Excellent Multimedia Summer Courses in Porur | Best Vacation Classes in Chennai
ReplyDeletePretty article! I found some useful information in your blog, it was awesome to read.
ReplyDeleteAdobe Photoshop Vacation Classes in Chennai | Best Technical Boot Camp in Chennai
ReplyDeleteGreat blog. You put Good stuff. All the topics were explained briefly. So quickly understand for me. I am waiting for your next fantastic blog. Thanks for sharing. Any course related details learn...
Php course in chennai
Hey, Wow Provided Post will be Very much Informative to the People Who Visit this Site. Good Work! Thank You for Sharing.
ReplyDeleteJoomla training in chennai
Nice and interesting article about "Introduction to PHP Tutorial".
ReplyDeleteData Science Training in Chennai
Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
ReplyDeleteGood discussion. Thank you.
Six Sigma Training in Abu Dhabi
Six Sigma Training in Dammam
Six Sigma Training in Riyadh
Great post and informative blog.it was awesome to read, thanks for sharing this great content to my vision.
ReplyDeleteGood discussion.
Java Training in Chennai
Java course in Chennai
Software Testing Training in Chennai
Web Designing Course in chennai
PHP Training in Chennai
Java Training in Tambaram
Java Training in OMR
Online casino BGAOC big winnings and lots of lucky games are waiting for you. all slot machine games successful do not wait, make your luck smile to you.
ReplyDeleteInteresting blog, it gives lots of information to me. Thanks for sharing such a nice blog.
ReplyDeleteData Science Course in Chennai
Data Science Training in Chennai
Machine Learning Course in Chennai
Machine Learning Training in Chennai
Azure Training in Chennai
Data Analytics Courses in Chennai
Data Science Training in Velachery
Data Science Training in Tambaram
great stuff, thanks for the blog
ReplyDeleteGerman Classes in Chennai
Big Data Training in Chennai
Android Training in Chennai
Selenium Training in Chennai
Digital Marketing Training in Chennai
French Classes in Chennai
French Classes in Adyar
Have been a long wait for this blog. Happy on reading. Do share more of this kind.
ReplyDeleteSpoken English Classes in Velachery
Spoken English in Velachery
Spoken English Classes in Tambaram
Spoken English Class in Chrompet
Spoken English Classes in OMR Chennai
Spoken English Classes in Perungudi
Spoken English Class in Ambattur
Spoken English Class in Avadi
Thanks to the admin for sharing this content with us. This blog was very helpful to me and gained some knowledge reading this.
ReplyDeleteGerman Classes in Mulund
German Language Classes in Mulund
German Classes in Mulund West
German Course in Mulund East
French Classes in Mulund
French Classes in Mulund East
French Classes in Mulund West
French Language Classes in Mulund
english to kannada typing
ReplyDeleteimo download for pc
ReplyDeleteimo download for pc
ReplyDeleteThe Blog is nice. every content should be very neatly represented.
ReplyDeleteData Science Training Course In Chennai | Data Science Training Course In Anna Nagar | Data Science Training Course In OMR | Data Science Training Course In Porur | Data Science Training Course In Tambaram | Data Science Training Course In Velachery
"exelent post
ReplyDeleteDigital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery
"
let’s download the latest version of monster legends mod apk V9.2.2 for Android with offers unlimited coins, gems & everything. What do you think first when you hear about ‘monsters?’ Deadly devils that are thirsty for blood and ugly creatures full of strength and cruelty. But these terms alone do not define monsters as a whole. Monsters are also known for their thrill and mysterious nature. keep it up
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
Thanks for sharing the information. It is very useful for my future. keep sharing.
ReplyDeleteDigital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery