Home  >  Article  >  Backend Development  >  Detailed explanation of PHP writing format (must read), Detailed explanation of PHP writing format must read_PHP tutorial

Detailed explanation of PHP writing format (must read), Detailed explanation of PHP writing format must read_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:50:42895browse

Detailed explanation of PHP writing format (must read), Detailed explanation of PHP writing format must read

Start with an example.

Launch the editor, create a php file and type the following code:

<&#63;php 
echo "你好!"; 
&#63;> 

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

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

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

As can be seen from this example:

•The PHP file or PHP code segment starts with "5ae7b5f89464a7f036233fb3f532493f", with the php code in the middle

•Each instruction set ends with ; symbol

•What the browser gets is the result after the PHP parser has executed the php code. Website viewers cannot view the original code of the php file

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

 
  
 PHP 测试 
  
  
 

<&#63;php echo "你好!"; &#63;>

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

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

Below we will introduce the output function of php.

PHP echo and print statements

Difference between echo and print:

•echo - can output one or more strings

•print - only allows output of a string, the return value is always 1

Tip: echo outputs faster than print, echo has no return value, and print has a return value of 1.

PHP echo statement

echo is a language structure, which can be used without parentheses or with parentheses: echo or echo().

1. Display string

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

<&#63;php 
echo "<h2>PHP is fun!</h2>"; 
echo "Hello world!<br>"; 
echo "I'm about to learn PHP!<br>"; 
echo "This", " string", " was", " made", " with multiple parameters."; 
&#63;> 

2. Display variables

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

<&#63;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]}"; 
&#63;> 

PHP print statement

Print is also a language structure that can use parentheses or not: print or print().

1. Display string

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

<&#63;php 
print "<h2>PHP is fun!</h2>"; 
print "Hello world!<br>"; 
print "I'm about to learn PHP!"; 
&#63;> 

2. Display variables

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

<&#63;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]}"; 
&#63;> 

The above detailed explanation of PHP writing format (must read) is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Bangkejia more.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1133104.htmlTechArticleDetailed explanation of PHP writing format (must-read), Detailed explanation of PHP writing format must-read. Start with an example. Start the editor, create a php file and type the following code: php echo "Hello!"; Name the file...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn