PHP writing format (mandatory). php writing details are mandatory.

Source: Internet
Author: User
Tags echo command php print

PHP writing format (mandatory). php writing details are mandatory.

Start with an example.

Start the editor, create a PHP file, and type the following code:

<? Php echo "Hello! ";?>

Name the file test. php and store it in the E: html directory.

Access the php file http: // 127.0.0.1/test. php in the address bar of the browser. The output result is as follows:

Hello! In this example, we use the echo command to output a string "Hello !".

From this example, we can see that:

• The PHP file or PHP code segment uses "<? Php, starting with "?>" End: php code in the middle

• Each instruction set ends with a; symbol

• The browser returns results after the PHP parser executes the php code. Website viewers cannot view the original php file code.

Of course, to output standard html code, you can complete the above example:

<Html> 

It can be seen that PHP code can be mixed with XHTML code.

Echo is a PHP built-in command used to output one or more strings. Similar to echo, there is print.

Next we will introduce the php output functions.

PHP echo and print statements

Difference between echo and print:

• Echo-one or more strings can be output.

• Print-only one string can be output, and the total return value is 1

Tip: The echo output speed is faster than print. echo does not return a value. print has a return value of 1.

PHP echo statement

Echo is a language structure. It can be used without parentheses, echo or echo ().

1. Display strings

The following example demonstrates how to use the echo command to output a string (a string can contain HTML tags ):

<?php echo "

2. Display Variables

The following example demonstrates how to use the echo command to output variables and strings.

<?php $txt1="Learn PHP"; $txt2="manongjc.com"; $cars=array("Volvo","BMW","Toyota");  echo $txt1; echo "<br>"; echo "Study PHP at $txt2"; echo "My car is a {$cars[0]}"; ?> 

PHP print statement

Print is also a language structure, which can be parentheses or not ().

1. Display strings

The following example demonstrates how to use the print command to output a string (a string can contain HTML tags ):

<?php print "

2. Display Variables

The following example demonstrates how to use the print command to output variables and strings:

<?php $txt1="Learn PHP"; $txt2="manongjc.com"; $cars=array("Volvo","BMW","Toyota");  print $txt1; print "<br>"; print "Study PHP at $txt2"; print "My car is a {$cars[0]}"; ?> 

The above PHP writing format (mandatory) is all the content shared by the editor. I hope you can give us a reference and support the help house.

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.