|
Once we already have installed PHP and MySQL, and the servant Apache formed to use them, we can begin to write our first script in PHP.
Example script php
<html>
<body>
<? php
$myvar = "Hello. East is my first script in PHP n";
//This is a comment
it is my first script in PHP n";
//This is a comment
I begin $myvar;
?>
</body>
</html>
Once written we save this in a file with the extension php, and place it in our servant, http://mi_servidor/php/test.php. Now if we put this URL in our navigator we will see a line with the text "Hello. East is my first script in PHP".
The first thing that we appreciate in the script are his delimitadores. In the first line of the script do we see <? php that indicates us that a script begins in PHP, and in the last one do we place?> to indicate the end of the script. It is necessary to emphasize that all the lines that one finds between these delimitadores must finish exactly and should eat, except the judgments of control (if, swicht, while, etc.).
Since in any programming, it is important to put many comments, for which if we want to comment on only one line we have to put at the beginning of the line//, if what we want is to comment on several we will use the delimitadores/* - */.
So that the servant I sent text we will use the instruction I begin, although also we can use printf of use similar to that of the C or Perl.
Finally, we see that the word myvar begins with the sign dollar ($). This symbol indicates to PHP that it is a variable. We have assigned a text to him to this variable, but also they can contain numbers or stage (arrays). It is important to remember that dollar begins all the variables with the sign. Also you will have observed that the text that we assign to him to the variable ends with n, this is not printed serves to indicate to the navigator a new line.
|