PHP syntax
The PHP script is executed on the server and the plain HTML results are sent back to the browser.
What are the PHP syntaxes?
PHP is a powerful embedded HTML scripting language that is often used by programmers as the basic language for website development. Basic knowledge points of PHP syntax include PHP script code tags, PHP instruction delimiters, PHP comments and PHP output.
Basic PHP syntax
PHP scripts can be placed anywhere in the document.
PHP script starts with <?php and ends with ?>:
<?php // PHP 代码 ?>
The default file extension for PHP files is ".php".
PHP files usually contain HTML tags and some PHP script code.
Below, we provide a simple PHP file example that can output the text "Hello World!" to the browser:
Example
<!DOCTYPE html> <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?> </body> </html>
Run Example»
Click the "Run Example" button to view the online example
Every line of code in PHP must end with a semicolon. A semicolon is a delimiter used to separate sets of instructions.
Through PHP, there are two basic instructions for outputting text in the browser: echo and print.
Comments in PHP
Instance
<!DOCTYPE html> <html> <body> <?php // 这是 PHP 单行注释 /* 这是 PHP 多行 注释 */ echo "Hello World!"; ?> </body> </html>
Run Example»
Click" Run instance" button to view the online instance