When a PHP Programmer starts to write a PHP snippet, the basic php syntax always starts with <?php and ends with ?>. You can place this snippet anywhere in the *.php document.
Some servers do support shorthand, in which case you can start with<? and end with ?> .
But for maximum portablitlity, I do recommend that you stick with the standard <?php rather than shorthand <? .
Heres an example:
<?php
echo “Hello, World”;
?>
4. Basic PHP Syntax
Today’s market is getting inundated new PHP websites each day. This means that there is a flux of new PHP Programmers joining the developers in creating and editing these new sites. What we will do is help these new developers gain an understanding of what the basics of PHP Programming are.
Here are a few of the materials covered in the Lessons:
Training
For the PHP Basics we are going to assume that your server has basic PHP support and that .php extensions are handled by PHP. If this is the case you’re ready to start as a PHP Programmer. One of the things I love about PHP is that I don’t have to compile anything. I don’t need any extra tools if I don’t want. Just a text editor and ftp program.
I like to think of PHP files as simple HTML documents that allow us to create tags to make the content come to life, dynamically. All you have to do is write the code and save the file to your server. That simple.
As you become more proficient and leave the PHP Basics, you will learn other tools and techniques to write your own code. For now we will just show you what it is to be new to the language.
Our next section covers How PHP Works. Thank you for taking time to read our PHP Basics section.
1. PHP Basics
When you browse to a website such as http://ctcoder.com/index.php, your ISP directs you to the server that holds the website information/files for CTCoder. The server will then read that index.php file and process the information contained within. PHP then tells the Client browser in the form of html. What this means is that PHP will create an HTML page dynamically based on what instructions the PHP Programmer wrote in the file.
This data is in the form of HTML that the browser can display as it would a standard HTML page. In short, PHP creates an HTML page on the fly based on parameters of my choosing; the server contains no static HTML pages.
In our next section we will cover what the php.ini file is used for: 3. The php.ini File
2. How PHP Works
This will show you how to customize the php.ini configuration file. This will control some settings of the PHP interpreter. This file enables you to such as global variables, register_globals.
How a php.ini File is Read
When PHP starts, it follows and behaves according to the specified settings of the available php.ini file. The server will look for this file in these locations in this order:
1. Within the directory that the page was loaded
2. The root directory (public_html or www folder)
3. The server’s default php.ini
Your server’s php.ini file will be used if you dont have a custom one created. You can find the default one in /usr/local/lib/php/php.ini. Check out these settings in the file as it may help you find the solution to problems you may be having on your server.
register_globals = On
The register_globals setting controls how users access your forms, server, and other variables. This variable is set to ‘off’. This means that you will have to use special arrays in order to access these variables.
NOTE: The reason for this is because when register_globals is set to On, your PHP scripts will become more vulnerable to attacks.
To retrieve the value of [input name="formVar"] from a form submitted with the POST method:
When register_globals = On
$theVariable = $formVar;
When register_globals = Off
$theVariable = $_POST['formVar'];
3. The php.ini File