PHP writing format, php writing

Source: Internet
Author: User
Tags echo command learn php php print

PHP writing format, php writing

Start with an example.

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

<? Phpecho "Hello! ";?>

Run

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:

  • In the PHP file or PHP code segment? Php, starting with "?>" End: php code in the middle
  • Each instruction set ends with a; symbol.
  • The browser returns the result after the PHP parser executes the php code. The website viewer cannot view the original code of the php file.

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. The returned value is 1 in total.

Tip:Echo outputs faster than print. echo does not return values. print returns 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 ):

<?phpecho "

Run

 

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]}";?>

Run

 

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 ):

<?phpprint "

Run

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]}";?>

Run

 

Address: http://www.manongjc.com/php/php_format.html

Related reading:

Php uses the filter_var () function to check whether the url contains a query string.

Php checks whether the IPv6 address is used

Php uses the filter_var () function to check whether a number is in the same range.

How does php ajax determine network disconnection?

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.