PHP

 Home  Computers & Internet  Web Programming PHP
What is PHP?
Echo
Comments
Variables
Constants
Data Types
number_format()
Character Strings
Mathematical Operators
Comparison Operators
Logical Operators
Joining Strings
explode()
implode()
strtolower()
strtoupper()
strlen()
ucfirst()
ucwords()
strrev()
str_replace()
str_repeat()
trim()
strip_tags()
addslashes()
stripslashes()
strpos()
strrpos()
nl2br()
isset()
unset()
empty()
POST
GET
If Statements
If Else Statements
Elseif Statements
Switch Statements
For Loops
While Loops
Do While Loops
Foreach Loops
File Create
File Open
File Read
File Write
File Delete
fgets()
file_get_contents()
Date & Time
$_SERVER
Sessions
Cookies
Arrays

HOW TO OUTPUT TO SCREEN WITH PHP USING ECHO

PHP has a built-in way to display output to screen. You would use an ECHO statement to output html to screen.

See this simple example.

<?
echo "John Smith";
?>

When you run this, it will output John Smith to your screen. PHP can also output HTML code as in the following example:

<?
echo "<b>John Smith</b>";
?>

When you run this, it will output John Smith (bolded) to your screen. Look at the page source for this. It will show: <b>John Smith</b>

What happens when you echo with PHP is that PHP processes this echo statement and sends the output to the web server which in turn sends this output to your browser. Also note that you web browser can only read html (it reads text but in html format) and not PHP. It is the PHP processor on the web server that reads PHP statements and then outputs it as HTML to your browser which then displays it for you to read off your screen.

Points to remember when using the echo statement:

  1. The echo statement starts with the word echo.
  2. Strings must be surrounded with single or double quotes (a string is a combination of characters, text or numbers).
  3. Numbers on their own do not need to be enclosed with quotes.
  4. Echo statement must be terminated at end line with a semi-colon.

Further examples:

Echo statementOutputs
echo "John Smith";John Smith
echo 'John Smith';John Smith
echo 699;699
echo "John Smith"error, no terminating semi- colon
echo John Smith;error, no enclosed quotes

Home | Privacy Policy | Terms Of Use | Contact Us