1. PHP basics

  • 1. PHP basics
    • 1.1.php runtime environment installation
    • 1.2. Common PHP code editor
    • 1.3.php markup style
    • 1.4. PHP comments
    • 1.5.php output statement

1.1.php runtime environment installation

An integrated development environment is the best place to start learning PHP, and the following are common ones

Integrated development software Available operating systems instructions
WAMP Win recommended
XAMPP Win/Mac
Mamp Mac recommended
Lamp Linux(CentOS/Fedora/Debian/Ubuntu)

WAMP : Under Windows, Apache+Mysql/MariaDB+Perl/PHP/Python, a group of open source software commonly used to build dynamic websites or servers, are themselves independent programs, but because they are often used together, have an increasingly high degree of compatibility. Together, they form a powerful Web application platform.

MAMP: MAMP PRO is a professional-grade version of OS X software for a classic local server environment on Apple. MAMP stands for Macintosh, Apache, MySQL, and PHP on apple’s OSX operating system. As the name suggests, you know MAMP is powerful. MAMP includes Apache server, PHP installation suite, and MySQL installation suite.

1.2. Common PHP code editor

  • VS Code
  • PhpStorm
  • Sublime
  • Zend Studio

1.3.php markup style

PHP supports a total of four markup styles

XML style (standard markup)


       
    echo 'the XML style'; PHP 7 only supports this markup style
? >
Copy the code

The recommended tag, which cannot be disabled by the server

② Script style

<script language="php">
    echo 'Script Style';
</script>
Copy the code

(3) short style

<? echo 'Short style'; ? >
Copy the code

(4) the ASP style

The < %echo 'the ASP style'; % >Copy the code

The above styles (②, ③, ④) are only available in PHP 5 or lower, and are no longer supported in PHP 7.

If you want to use short style and ASP style tags, you need to set them up in the php.ini file. Ini file, set short_open_tag and asp_tags to On, and restart the Apache server.

1.4. PHP comments

PHP supports three styles of program comments.

// Single line comment (style C)

/* multi-line comments, note: cannot nest c++ style */  

# Single line comment (Shell style)
Copy the code

1.5.php output statement

Common ones are echo, print, print_r(), and var_dump().

Echo: Outputs one or more strings, expressions, variables, and constant values to the page. It is not a function. Do not use parentheses.

echo 'true';              // Output result: true
echo 'result='.4 + 3*3;  // Result =13
Copy the code

Print: Print is used in the same way as echo. (1) Echo can print multiple strings, print can print only one string. (2) Echo output is faster than print. Echo returns no value, print returns 1.

print 'best'; // Output result: best
Copy the code

Print_r () : is a built-in PHP function that can output any type of data, such as strings, arrays, and so on.

print_r('best'); // Output result: best
Copy the code

Var_dump () : Not only can you print one or more arbitrary types of data, but you can also get the type and number of elements of the data.

var_dump(2);          Int (2)
var_dump('php'.'c');  Output: string(3) "PHP" string(1) "c"
Copy the code