ch-2 Output
There are mainly two language
construct available in php for print:
a.
echo
b.
print
Pay attention here,
echo and print is a language construct not a function. Because print and echo no need to follow with
brackets. Eg.
echo :-
<?php
echo “hello World”;
?>
This Program simply
print:
hello World
print:
You may also use print function in php to print same
statement “hello world” like:
<?php
print “hello World”;
?>
This Program code also
simply print:
hello World
In both statement if you don’t use parenthesis, then
it will show error ,
But if there you want to print single word like “hello”
only then it is allow, it means only
single word without double quotes(“ ”)is allowed , or can say that “white space
“ is not allowed without double quotes(“ ”).
eg.
print hello;
O/p->hello
Cannot use white space
print hello world;
You saw in uppercase both (print and echo) function works
or print same thing, but both function
echo and print have some technical difference , for ex.
print
|
echo
|
Print return 1 integer eg.
$a=print “hello”;
echo $a;
O/P-> hello 1
|
echo return void eg.
$a=echo “hello”;
echo $a;
O/p- error
|
Words separate with comma is not work.eg.
print “hello”,”world”;
O/p-> error
|
But, echo is work in sepration(,) eg.
echo “hello”,”world”;
O/p-> helloworld
echo also work in separation by (,)here by without double
quotes(“ ”) eg.
echo hello, world;
O/p->helloworld
|
print is slow
then echo
|
echo is slightly faster than print
|
print command also has a short syntax like:
<? ="hello
world"; ?>
This statement also
print hello world.
printf():
printf is a function ,
used for print argument. This is always followed by braces () .
if you have only one
argument to print then , no need double quotes(“ “) around argument for eg.
<?php printf(hello); ?>
But if you have more
than one argument to print, you need to put double quotes(“ “) around the
argument. for eg.
<?php printf(“hello world”); ?>
Comments
Post a Comment