PHP and MySQL (2) Basic syntax and commands
For anyone who has used C, C ++, Java, JavaScript, Perl, or other languages from C, PHP syntax will make you very familiar. A PHP script contains a series of commands (statements) that the Web server must process in sequence. Like other languages mentioned above, PHP statements always end with a semicolon.
This is a typical PHP statement:
This statement calls a built-in function called echo and passes it the following string: "This isTest! ". Built-in functions can be understood as "you can know how to do it without additional instructions on PHP. PHP has many built-in functions. we can use them to do many things, from sending e-mail to processing different types of data stored in the database. The echo function simply inserts the text passed to it into the current location of the HTML page. You can look at the following example:
Simple PHP Example
Test! ");?>
|
If you name this code as test. php (or test. php3, if your Web host has not. PHP file configured as a PHP script), and place it on your Web server, the browser will see this page:
Simple PHP Example
This isTest!
|
Note that contains the HTML identifier (And.
You may wonder why we should use brackets and quotation marks here. In PHP, quotation marks are used to mark the start and end of a string. Parentheses have a double effect. First, it indicates that echo is a function you want to call. Second, it indicates the start and end of the function parameter. Through parameters, you can direct your function to what to do. For the echo function, we only need to give it a string for display on the page, but we will see that some functions have several parameters (in this case, separate parameters with commas ). Even for functions without parameters, we still need brackets, but we do not have to enter anything in the brackets.