PHP Echo () function

Source: Internet
Author: User
Tags configuration settings parse error

Instance

Output text:

<?phpecho "Hello world!";? >

Definition and usage

The Echo () function outputs one or more strings.

Note: the Echo () function is not actually a function, so you do not have to use parentheses on it. However, if you want to pass more than one argument to echo (), using parentheses will generate a parse error.

Tip: the Echo () function is slightly faster than print ().

Tip: the Echo () function also has a shorthand syntax. Before PHP 5.4.0, this syntax only applies when Short_open_tag configuration settings are enabled.

Grammar
Echo (strings)
Parameters Description
Strings Necessary. One or more strings to send to the output.
Technical details
return value: no return value.
PHP version: 4 +
More examples of examples 1

Write the value of the string variable ($STR) to the output:

<?php$str = "Hello world!"; Echo $str;? >

Example 2

Writes the value of the string variable ($STR) to the output, including the HTML tag:

<?php$str = "Hello world!"; echo $str; echo "<br>what a nice day!";? >

Example 3

Connect two string variables:

Example 4

Write array values to output:

<?php$age=array ("Peter" = "+"); echo "Peter is". $age [' Peter ']. "Years old.";? >

Example 5

Write the text to the output:

Example 6

How to use multiple parameters:

Example 7

The difference between single and double quotation marks. Single quotes will output the variable name instead of the value:

<?php$color = "Red", echo "Roses is $color", echo "<br>"; Echo ' Roses is $color ';? >

Example 8

Simplified syntax (only for cases where Short_open_tag configuration settings are enabled):

PHP Echo () function

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.