PHP Tutorial: php echo function

Source: Internet
Author: User
Tags echo command php tutorial

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 ";
?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.