echo is very important in PHP, although it seems simple syntax is simple, but the echo function is often used in the program, it is used for the loss, variables, strings, constants, HTML and so on;
As you can see in the past lesson, the PHP command Echo is a means of outputting text to the Web browser. Throughout your career, your PHP will use the echo command over any other. Let's give it a solid read!
Output characters:
Output a string, just like we learned in the previous lesson, using the PHP echo. You can put any string variable or you can use quotes, just like we do below, create a string that the Echo function will output.
<?php
$myString = "hello!";
Echo $myString;
echo "?>
Output to www.111cn.net!
In the example above, we output "Hello!" Smooth Text output that we are sending to the user in the form of a page, so it is important that we use the appropriate HTML syntax!
In our second echo statement, we used echo to write a valid first five HTML speech. To do this, we just put the
Careful when Echoing quotes!
It is cool that you can output HTML with PHP. However, you must be careful to use HTML code or any other string, including quotes! Echo uses quotes to define the beginning and end of the string, so you must use one of the following policies if your string contains a quote:
Do not use a string within quotation marks
Escape your quote is a string within the backslash. In order to escape the quote just place the straight backslash front quotes, that is, "
The string within the quotation mark (apostrophe) with single quotes.
See our example below for the correct and wrong use of Echo:
<?php
This won ' t work because of the quotes around specialh5!
echo "
OK because we escaped the quotes!
echo "
OK because we used an apostrophe '
echo "
?>
Look at the echo output variable.
<?php
$my _string = "Hello Bob." My name is: ";
$my _number = 4;
$my _letter = A;
echo $my _string;
echo $my _number;
echo $my _letter;
?>
Output Result: 4a
The string and the variable are both output.
You can also make internal variable double quotes for strings (for example, "here and string of dollar variables"). Putting a variable inside the quotation mark ("") tells you that it is PHP and that you want to catch the string value of the variable and use it for the string. The following example shows an example of this cooling function.
<?php
$my _string = "Hello bob. My name is:";
echo "$my _string Bobettta <br/>";
Echo Hi, I ' m bob. who are for you? $my _string <br/> ";
Echo Hi, I ' m bob. who are for you? $my _string Bobetta ";
?