home

Php Output Data Tutorial


The easiest way we can output data in PHP is using a Language Construct known as echo. Constructs are elements that are built into language. 'echo' can be used for outputting any data. It can also be used to output HTML

Example of PHP echo:

<?php
echo "this is my first message.";

/* output: this is my first message. */
?>

PLEASE NOTE:

The above example will show this message on webpage. this is my echo message.

You can use echo to output some HTML code:

<?php
echo "<p>this is my first paragraph.<p>";
echo "<p>this is my second paragraph.<p>";
echo "<p><strong>this is some bold text.</strong><p>";
/*
this is my first paragraph.

this is my second paragraph.

this is some bold text.
*/

?>

 

Other ways to output in PHP: print(), printf()

Another construct to output data is print:

<?php
print "<p>this is a paragraph 'printed' without parenthesis.<p>";
print( "<p>this paragraph is \"printed\" using parenthesis.<p>" );
/*
this is a paragraph 'printed' without parenthesis.

this paragraph is "printed" using parenthesis.
*/

?>

PLEASE NOTE:

A more complex way to output and format data is the printf() function:

<?php
//declaring a variable $myName = "John Doe";
printf
("<p>Hello, my name is <strong>%s</strong>.<p>", $myName);
/*
Hello, my name is John Doe.
*/

?>

PLEASE NOTE:


Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

Copyright © 2014 by Cramerz.com.