PHP Basic Teaching Echo command

Source: Internet
Author: User
Tags echo command
This article introduces the most basic command in PHP programming, that is, the specific use case of the echo command, for your reference.

PHP commands echo to output text to a Web browser as a means.

Throughout your PHP career, you will use the echo command more often than any other command.

So let's give it a solid read it carefully and carefully!

Output a string

To output a string, just like we did in the previous lesson, use the echo of PHP.

You can put one of the string variables, or you can use quotation marks, like we do below, to create a string echo function will output.

Code:

 
      I like php! ";? >

Results: hello! I like php!

In the example above, we output "hello! Smooth Our output text is sent to the user in the form of a webpage, so it is important that we use proper HTML syntax!

We use echo to write a valid header 5 HTML statement in our second ECHO statement. To do this, we simply put

Begins the string and closes it at the end of the string. Just because you use PHP to make a webpage doesn't mean you can forget HTML syntax!

Be careful to echo the quotes! HTML and PHP can be exported. However, you have to be careful when using HTML code or any other string, including quotation marks! Echo uses quotation marks to define the beginning and end of a string, so you must use one of the following strategies if your string contains quotation marks:

Do not use quotes inside of your string

Escape your quotation marks with a backslash in the string. Just to escape the quotation marks, place a backslash directly before the quotation mark, that is, the string inside the quotation mark uses single quotation marks (apostrophes). Please refer to the following example for correct and incorrect use back display:

Code:

  
       I Love using php!

"; OK because we escaped the Quotes!echo "

I Love using php!

"; OK because we used an apostrophe ' echo '

I Love using php!

";?>

If you want to output a string that includes quotation marks, use single quotation marks (') or escape the quotation marks before it places a backslash (\ "). The backslash tells PHP that you want the quotation mark to be used, and that the string is not used to end the echo.

It is easy to agree on variables that echo variables . The development of PHP language puts some extra work into the common task of making all the variables almost infallible! No quotation marks are required, even if the variable does not hold the string. The following is the correct format for the echo variable.

Code:

 
      

Result: Hello Bob. My name is:4a

echo Variables and text strings

You can also enclose the inside of a double-quoted string variable (such as "string and variable"). By putting a variable inside the quotation mark (""), you are telling PHP that you want it to grab the string value of the variable and use it in the string. Take a look at the following example. Code:

 
      "; echo" Hi, I ' m Bob.  
"; echo" Hi, I ' m Bob. Who is? $my _string Bobetta ";? >

Result: Hello Bob. My name Is:bobettahi, I ' m Bob. Who is? Hello Bob. My name Is:hi, I ' m Bob. Who is? Hello Bob. My name Is:bobetta

By adding a string variable inside, you can save yourself some time to make your code easier to read, but it does take some time to adapt. Remember to use double quotes without grabbing the string value of single quotes. Single quotes will just output variable name strings, like) $ my_string, instead of (Hello my name is Bob.) :)。

the echo of PHP-not a function of ECHO is not a function, but rather it is a language structure. When you use functions in PHP, they have a very special form, which is what we are going to be after. Now, just know that ECHO is a special tool that you will come to understand and love!

This command about echo echoing in PHP is introduced here, and we hope to help you.

  • 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.