Basic syntax and commands
For anyone who has used C, C + +, Java, JavaScript, Perl, or any other language originating from C, PHP's syntax will make you feel very familiar. A PHP script contains a series of commands (statements) that the Web server must process in turn. Like the other languages mentioned above, PHP statements always end with a semicolon (;).
This is a typical PHP statement:
Echo ("This is a test!"); |
This statement invokes a built-in function called Echo and passes it to such a string: "This is a test!" ”。 Built-in functions you can understand the "do not need another explanation of PHP can know how to do" thing. PHP has a lot of built-in functions that we can use to do a lot of things, from sending e-mails to processing the different types of data stored in the database are their jurisdictions. The Echo function simply inserts the text passed to it into the current position of the HTML page. You can take a look at the following example:
Simple PHP Example
Test! ");? >
|
If you name this code test.php (or TEST.PHP3, if your web host has not yet configured the. php file as a PHP script) and put it on your Web server, the browser will see a page like this:
Simple PHP Example
This is a test!
|
Note that all text including the HTML identifier ( and ) is displayed correctly.
You may wonder why we use parentheses and quotes here. Quotation marks are used in PHP to mark the beginning and end of a string. Parentheses have a double effect, first of all, it indicates that echo is a function you want to call, and secondly, it marks the beginning and end of the function's arguments. Through the parameters, you can direct your function to what to do. For the echo function, we just need to give it a string to display on the page, but we'll see that some functions have several parameters (in this case, we separate each parameter with commas). Even for functions that have no arguments, we need to have parentheses, except that we don't have to enter anything in the middle of the parentheses.