This article introduces the most basic command in php programming, that is, the specific use case of the echo command, for your reference. PHP command echo is a means of outputting text to a Web browser. Throughout your PHP career, you will use echo commands more frequently than any other commands. So, let's give it a solid and careful reading! Output a string Output a string, just as we did in the previous course, using PHP echo. You can use either a string variable or a pair of quotation marks to create a string echo function for output under a string like ours. Code:
Result: Hello! I like PHP! In the above example, we output "Hello !" Smooth. The output text is sent to a webpage in the form of a user, so it is important that we use the appropriate html syntax! In our second echo statement, we use echo to write a valid header 5 HTML statement. To do this, we simply start the string and close the string at the end. Just because you use PHP to make webpages do not mean you can forget the HTML syntax! Carefully echo the quotation marks!HTML and PHP can be output. However, you must be careful when using html code or any other string, including quotation marks! Echo uses quotation marks to define the start and end of a string, so you must use one of the following policies if your string contains quotation marks: Do not use your string in quotation marks Escape your quotation marks by using a backslash in the string. In order to avoid quotation marks, place a backslash before the quotation mark, that is, the character strings in the \ "quotation mark are enclosed in single quotation marks (apostrophes ). See the following example for correct and incorrect display: Code:
If you want to output a string that contains quotation marks, use single quotation marks (') or escape quotation marks. put a backslash (\ ") in front of it. The backslash tells PHP that you want to use it in quotation marks. the string is not used to end the echo string. Echo variableIt is easy to agree with variables. The development of PHP language has invested some extra work to make all the variables almost echo the same common task! No quotation marks are required, even if the variable does not hold a string. The following are the variables in the correct format. Code:
Result: Hello Bob. My name is: 4a. Echo variable and text string You can also set the double quotation mark string variable (such as "string and variable "). By putting the quotation marks ("") in a variable, you are telling PHP that you want it to capture the string value of the variable and use it in the string. Let's look at the example below. Code:
";echo "Hi, I'm Bob. Who are you? $my_string ";echo "Hi, I'm Bob. Who are you? $my_string Bobetta";?> Result: Hello Bob. My name is: BobettaHi, I'm Bob. Who are you? Hello Bob. My name is: Hi, I'm Bob. Who are you? Hello Bob. My name is: Bobetta By adding a string variable, 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 quotation marks instead of the string value of single quotation marks. Single quotes will only output the variable name string, like) $ my_string), instead of (hello, my name is Bob. :). PHP echo-not a functionEcho is not a function, but a language structure. When you use functions in PHP, they have a very special form, which is what we will be after. Now, you only need to know that echo is a special tool and you will understand and love it! This is an introduction to the echo command in php. I hope it will be helpful to you. |