As you can see in the previous PHP code example, the echo command is used to display text into the browser. A text or string can be written in the browser by directly writing it in echo enclosed in two double quotes or by storing the string or text first in a variable and then writing it in echo. Here is an example:
Example:
<?php
$StringKu = "Hello!";
echo $StringKu;
echo "<h5>I love using PHP!</h5>";
?>
Important!! - Be careful when writing a string that contains double quotes using echo. In echo, quotes are the beginning and end markers of the text/string that will be written with echo, so you must pay attention to the following:
- Do not use quotation marks in text that will be written with echo
- If you still want to write quotes in the text that will be written with echo, then put a slash "\" in front of the quotes.
- In addition, you can also use single quotation marks (apostrophes) to replace quotation marks in text.
Example:
echo "<font face=\"verdana\" size=\"4\">Tampilan 2- \"I love using PHP!\"</font>";
echo "<br>";
echo "<font face='verdana' size='4'>Tampilan 1 - I love using PHP!</h5>";
echo "<br>";
Results:
Writing a quote ( " ) by adding a slash ( \ ) in front of it, this also applies when you want to fill it in a variable.
Example:
$tes = "\"tes\"";
echo "$tes";