The
echo command provides you with a way to output your
string variables. It is a vital part of the PHP language
mainly based on it use for outputing error messages
as well as outputing success messages. By the end
of this tutorial you should be able to integrate this
into a project.
First
off, you can use a string variable or use quotes (single
and double) to display your echo. Below we have used
both:
|
<?php
$string
= 'test 1';
echo $string;
echo 'test 2';
?> |
|
Outputs
the following: test 1 test 2
Don't
Create A Problem, Keep Reading!
One
major issue with the echo command is people typically
output HTML with it. Adding HTML is actualy a great
use of this tool but most people run into problems
with certain codes.
When
using codes like for instance <font face="tahoma">
in echo ""; they run into an error because
they are using double quotes. The best way to fix
this would be using a "\" or simple using
the opposite (i.e: single and double).
If
you are writing something in email for instance and
have a long amount of text that needs paragraph spacing
you can use a period. Look below:
|
<?php
$string
= "test 1" .
"\r\n\n" . "test 2" .
"\r\n" .
"test3";
echo $string;
?> |
|
This
will ensure you receive your spaces without creating
a problem with the quotes.
If
you have more questions on this please ask in the
discussion board!
Go
Back To PHP Tutorials