TUTORIALS » PHP / MySQL » PHP essentials (guided tutorials)Starting with PHPPage 1 of 2
PHP—just as any other programming language—is divided in instruction lines, each line contains one instruction and ends with a semicolon (;). Failing to end each instruction line with the semicolon will cause the script to return an error and stop.
Strings and echoThe first PHP instruction you are going to learn is the functionecho. In PHP echomeans something like "send the following text to the browser". Let's take a look at an example: <?php echo 'Hello World <br />'; echo "How are you?"; ?> There are two instruction lines in the example code. In each one I am starting with the instruction echofollowed by a string. A string is a set of alphanumeric characters, in other words, a text. Notice how both strings are placed between quotation marks. The string in the first line is placed between single quotes and the second string is placed between double quotes. Then each instruction ends with a semicolon. What is the difference between single and double quotes for strings in PHP? I will explain that in another tutorial, but don't go there just yet; there is more to learn first. For now let's just say that all strings in PHP must be place between quotation marks. Now it is time for you to practice your first PHP script. Read this before you start your practice
Do you remember how, when you created HTML files, you could simply double click on the .html file inside your computer and the browser would automatically open, displaying the rendered content of your file? Well, PHP is different.
Remember, PHP scripts are processed by the server, not by the browser; so all .php files must be uploaded to the server and accessed by entering the URL path into the address bar of your browser. Example: http://www.your-domain.com/your-file.php Also, make sure PHP works on your server.
You are right! It is not the same. Before you started with PHP, all the .html files you created were sent to the browser unprocessed, so the sources presented by the browser and your actual .html files were pretty much the same. Now, when we work with .php files, the server processes all the instructions and sends only the results of this process. In this case: Hello World <br /> How are you? Now follow into the next page of this tutorial!
|
|