When we learn the programming language, whether it is PHP, or JavaScript, or HTML, they each writing format is different, we first want to learn is their writing format, today we will take you to learn the PHP format of writing!
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 in the browser address bar: http://127.0.0.1/test.php, the output is as follows:
How are you doing! In this example, we output a string with the echo command "Hello!" ”。
As you can see from this example:
php file or PHP snippet begins with "<?php" and ends with "?>" with PHP code in the middle
• Each instruction set to; End of symbol
• The browser gets the PHP parser after executing the PHP code results, the site viewer can not see the original PHP file code
Of course, to output the standard HTML code, the above example can be perfected as:
The PHP code can be seen to be mixed with XHTML code.
Echo is a PHP built-in instruction for outputting 1 or more strings, similar to echo and print.
Below we introduce the output function of PHP.
PHP Echo and Print statements
Echo and Print differences:
echo-can output one or more strings
print-allows only one string to be output, with a total of 1 return values
Tip: The echo output is faster than print, ECHO has no return value, and print has a return value of 1.
PHP Echo Statement
Echo is a language structure that can be used without parentheses or parentheses: Echo or Echo ().
1. Display string
The following example shows how to use the echo command to output a string (the string can contain HTML tags):
<?php echo "
2. Display variables
The following example shows how to use the echo command to output variables and strings.
<?php $txt 1= "Learn PHP"; $txt 2= "manongjc.com"; $cars =array ("Volvo", "BMW", "Toyota"); echo $txt 1; echo "<br>"; echo "Study PHP at $txt 2"; echo "My car is a {$cars [0]}";?>
PHP Print Statement
Print is also a language structure, you can use parentheses, or you can use no parentheses: Print or print ().
1. Display string
The following example shows how to use the Print command to output a string (the string can contain HTML tags):
<?php print "
2. Display variables
The following example shows how to use the Print command to output variables and strings:
<?php $txt 1= "Learn PHP"; $txt 2= "manongjc.com"; $cars =array ("Volvo", "BMW", "Toyota"); Print $txt 1; print "<br>"; Print "Study PHP at $txt 2"; Print "My car is a {$cars [0]}";?>
Summarize:
This article introduces the PHP format of the writing essentials, I believe you have a certain understanding of writing PHP format, I hope you have some help!
Related recommendations;
A very full phpcms and PHP format timestamp tutorial
What file is PHP? How do I open it? Four ways to open PHP format files (figure)
Recommended 10 articles for PHP format