|
|
|---|
Are we ready?Assuming that your installation went smooth and you are now ready to begin, let's start with some basic understanding of PHP files. You must understand and remember few things about creating PHP files. And these are:-
Your first PHP codeWhy not display some output onto the screen? It is in fact much easier to accomplish with PHP. All you have to do is use PHP language construct called echo and we are done. Here's how.. Open a blank new file in your editor or notepad and write the below mentioned lines in the file. Then save the file with a .php extension. If you are using notepad as editor then be careful about the file extension. In Windows OS the file extensions are often hidden, so you must ensure that file saved has a .php extension. Ok, take a look at the code below..
<? echo "This is my first line!"; ?>Now save the file and upload it to the correct location in the web server and call it. The url could be http://localhost/filename.php (just an example, replace 'localhost' and filename.php with actual.) Great! What do you see? We expect to see an output which will look like.. This is my first line! If that is the exact output on your browser, then it is a success!!! We are on a good start. If you did not see this output, then perhaps PHP was not installed/configured properly. Note that if the PHP file is prompted to be downloaded in your browser, then PHP is not installed/configured properly as the file with .php extension is not being parsed. Please refer to your installation procedure. Case SensitivityAll the keywords and built-in constructs are case in-sensitive. Which means, there is no difference between echo and ECHO Handling StatementsAll statements are separated using a semicolon. It's only a compound statement such as if loop or a conditional loop which does not need a semicolon before and after the closing bracket. For example:
<?phpCommenting the codeCode require commenting for a many reasons. The commented code is not parsed by PHP and is a good way of adding comments about statements, code and functions. All lines starting with // will be treated as a comment by PHP. One can also using # to comment the code. Example:
<?phpNow you know that the text in first line and third line after // are treated as comments. |
|
|
|---|