8 PHP 5 echo and Print statements

Source: Internet
Author: User
Tags echo command learn php php print
In PHP, there are two basic output methods: Echo and Print.

PHP Echo and Print statements

The difference between Echo and print:

echo - 能够输出一个以上的字符串print - 只能输出一个字符串,并始终返回 1

Tip: Echo is slightly faster than print because it does not return any values.

PHP Echo Statement

Echo is a language structure that can be used with or without parentheses: Echo or Echo ().
Display string

The following example shows how to display different strings with the echo command (also note that the string can contain HTML tags):


    
     echo"

PHP is fun!

";echo"Hello world!
";echo"I'm about to learn PHP!
";echo"This", " string", " was", " made", " with multiple parameters.";?>

The following example shows how to use the echo command to display strings and variables:


   
    $txt1="Learn PHP";$txt2="W3School.com.cn";$cars=array("Volvo","BMW","SAAB");echo$txt1;echo"
";echo"Study PHP at $txt2";// 单引号解析不了变量$echo"My car is a {$cars[0]}";?>

PHP Print Statement

Print is also a language structure and can be used with or without parentheses: print or print ().
Display string

The following example shows how to use the Print command to display different strings (also note that the string can contain HTML tags):


    
     print"

PHP is fun!

";print"Hello world!
";print"I'm about to learn PHP!";?>

Show variables

The following example shows how to use the Print command to display strings and variables:


   
    $txt1="Learn PHP";$txt2="W3School.com.cn";$cars=array("Volvo","BMW","SAAB");print$txt1;print"
";print"Study PHP at $txt2";print"My car is a {$cars[0]}";?>

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the 8 PHP 5 echo and Print statements, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.

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