Ch-4 Basic of PHP Script
PHP syntax:
Php script
can only be write within (<? Php
?> ) tag, save by .php extension and save in xampp\htdocs.
For example
: if you want to print hello world , you have to do following-
Open notepad
or notepad++, then write there following
code:
<?php
echo “hello world”;
?>
Save this
program by any name suppose test1 and also this name is followed by .php
extension. Like(test1.php) .
This program simply print hello world on PHP Server.
Echo
echo is a
print command. In place of echo you may be write print. For ex.
<?php
print "good morning";
?>
Output :good morning
Print and echo
Remember that, echo and print is a language
constructs not a function. Function is always followed by () parenthesis.
In echo and
print , this is your wish to apply or not apply () parenthesis with them.
Both are a
language constructor . both can be write without double inverted quotes(”), but
remember without quotes you cannot write more than one word. For example
<?php
print good;
?>
Output :good
There is
also no necessity to apply semicolon(;) at end of instruction.
Difference between echo and print:
1. echo
does not have return argument, but print have a return argument 1. So, we can
say that echo is faster than print.
2. echo can consider more than one
string like:
<?php
echo
"good","morning";
?>
Output
:good morning
But print
cannot consider more than one string
<?php
print "good","morning";
?>
It gives a parse error.
Use of HTML in PHP
In case, if
you want to design your page by background color,text color etc , you have to embedded
this tag within html program. Like:
<html>
<head><title>first
program</title></head>
<body bgcolor="red" text="green" >
<?php
echo "hello world";
?>
</body>
</html>
Technical Interview Question
1. How can PHP and HTML interact?
2.What are the main error types in PHP and how do they differ?
3. What is "echo" in PHP?
4.What is "print" in PHP?
5. What is the difference between "echo" and "print" in PHP?
1. How can PHP and HTML interact?
2.What are the main error types in PHP and how do they differ?
3. What is "echo" in PHP?
4.What is "print" in PHP?
5. What is the difference between "echo" and "print" in PHP?
No comments:
Post a Comment