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?