Hello All,
I want to know the exact difference between echo,print and printf
I want to know weather print if a function or not.
Thanks,
| SitePoint Sponsor |



Hello All,
I want to know the exact difference between echo,print and printf
I want to know weather print if a function or not.
Thanks,
Barbara





Print is not a function, but a language construct.
Echo tends to be insignificantly faster than print.
Never used printf.




I just took some tests:
with both print and echo.PHP Code:$execution_start = microtime(true);
echo '<ul>';
for ($i=0; $i<10000; $i++)
{
echo '<li>new string ' .$i. '</li>';
}
echo '</ul>';
$execution_end = microtime(true);
$execution_time = $execution_end - $execution_start;
print '<p>took: ' . round($execution_time,4) . ' seconds</p>';
I executed 10 times for each function and these are the average results:
Rather insignificant indeedCode:echo: 0.09278 seconds print: 0.09146 seconds![]()



I come to know that printf is a function which returns the value of 1 or 0
depending upon success.
But still I am having doubt in echo and print.
Barbara





For all practical purposes, I think you can use any of them, echo or print, without any concern.
echo returns no value
print returns a success value
printf prints a formatted string
For example:
PHP Code:printf("Hello %s\n", $name);
Bookmarks