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.