You are on page 1of 1

PHP Code:

<?php
// This won't work because of the quotes around specialH5!
echo "<h5 class="specialH5">I love using PHP!</h5>";

// OK because we escaped the quotes!


echo "<h5 class=\"specialH5\">I love using PHP!</h5>";

// OK because we used an apostrophe '


echo "<h5 class='specialH5'>I love using PHP!</h5>";
?>

If you want to output a string that includes quotations, either use an apostrophe ( ' ) or escape the
quotations by placing a slash in front of it ( \" ). The slash will tell PHP that you want the quotation to be used
within the string and NOT to be used to end echo's string.

Echoing Variables

Echoing variables is very easy. The PHP developers put in some extra work to make the common task of
echoing all variables nearly foolproof! No quotations are required, even if the variable does not hold a string.
Below is the correct format for echoing a variable.

PHP Code:
<?php
$my_string = "Hello Bob. My name is: ";
$my_number = 4;
$my_letter = a;
echo $my_string;
echo $my_number;
echo $my_letter;
?>

Display:
Hello Bob. My name is: 4a

Echoing Variables and Text Strings

You can also combine text strings and variables. By doing such a conjunction you save yourself from
having to do a large number of echo statements. Variables and text strings are joined together with a period( .
). The example below shows how to do such a combination.

You might also like