Home > Backend Development > PHP Tutorial > PHP writing format, php writing_PHP tutorial

PHP writing format, php writing_PHP tutorial

WBOY
Release: 2016-07-12 08:51:44
Original
1042 people have browsed it

PHP writing format, php writing

Start with an example.

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

<?php
echo "你好!";
?>
Copy after login

Run

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:

<code class="language-php hljs">你好!</code>
Copy after login

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 "", 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 测试
 
 
 

<?php echo "你好!"; ?>

Copy after login

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

The difference between echo and print:

  • echo - can output one or more strings
  • print - only allows to output 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):

<?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.";
?>
Copy after login

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

Run

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

<?php
print "<h2>PHP is fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>
Copy after login

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

Run

Original address: http://www.manongjc.com/php/php_format.html

Related reading:

php uses the filter_var() function to detect whether the url contains the query string

php detects whether it is an IPv6 address

php uses the filter_var() function to detect whether a number is within a range

How does php ajax determine that the network connection is disconnected

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1128380.htmlTechArticlePHP writing format, PHP writing starts with an example. Start the editor, create a php file and type the following code: ?phpecho "Hello!";? Run Name the file test.php and save it...
Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template