Now let’s write and run some basic programs in PHP.
Program 1: Program to print “Welcome to php” in PHP.
Open notepad++ and write below lines of code:
echo “Welcome to php”;
Save this program in C://xampp/htdocs/welcome.php
Note: if xampp is not installed in C:// then save your program which ever drive xampp installed.
Don’t forget to start Apache from xampp controller panel whenever you want to run the PHP coding.
Open you browser and type following url : localhost/welcome.php
Explanation: PHP Code starts with “<?php” tag and ends with “?>” tag.
“echo” is use to display string or value on page.
Program 2: print function.
print “print is a function”;
print is function
Explanation: “print” is a function to display string or value on page.
Question: Now the Question is what the difference between echo and print?
echo can take and output multiple strings (See in Program 3).
print can’t output multiple string.
echo is marginally faster than print.
echo not return any value.
print return value either 0 or 1.
Program 3: echo with multiple strings.
echo “Hello Jhon “,”how are”,” you”;
Hello Jhon how are you
Program 4: Print new line with the help of </br> tag.
echo “Going to start a new line”;
echo “</br> I am in new line.”;
Explanation: <br> is a html tag, can use in PHP for next line.
Going to start a new line
I am in new line.