Introduction to PHP Programming
Getting Started With PHP
PHP is a language for easily building dynamic web pages. It provides an easier way to accomplish web related programming tasks, which are accomplished only with difficulty in more complex and powerful languages, such as Perl or C. It is ideally suited to the web because PHP scripts live inside web pages right along with the HTML tags and content. For that reason, PHP is called an embedded scripting language. Developers can embed programs in their web pages, making the dynamic. They can treat programs just like web pages. PHP pages can contain both regular HTML and PHP code. This allows you to develop web applications quickly. However, unlike some web scripting languages, PHP makes a clear distinction between sections of PHP code and sections of the HTML document. When the web server fills a request for a PHP enabled page, it first looks through the page content for sections of PHP code and executes any it finds. Any normal HTML sections are passed to the browser without any changes. This means that you can freely mix snippets of program into a web page anywhere.
Why Use PHP?
Here are a few good reasons to choose PHP for enabling interactive content on your web site (besides being open source):
- You don't have to know any special commands to compile your program, it runs right in your web browser.
- You don't have to know everything there is to know about PHP to start writing useful programs.
- The data types and structures of PHP are easy to use and understand, PHP knows what you mean and can convert types automatically.
- PHP is included in most web hosting plans, it can run on Linux and Windows
- Because it uses similar syntax and constructs, knowledge of PHP can help you in learning the C language.
PHP serves as a "wrapper" for many standard C libraries, which are easily compiled into the language giving it the flexibility to respond more rapidly to changes in web technology or trends.
Things you can do in PHP can be done in other languages, but PHP was designed to work in a web context, so things that are difficult or tedious for the applications programmer to "roll their own" in Perl (my favorite language) are easy in PHP. PHP enabled web sites can be deployed with amazing rapidity, due to its being tuned for dynamic pages and database backends.
You don't have to know everything there is to know about PHP before you can write useful programs. So we will start with a few simple examples.
Embedding snippets of code into a web page has many uses. For example, in an otherwise static web page you may obtain the value of a variable and later use it to dynamically change the content of the page. This PHP example displays the text identifying the web browser on a web page:
$browser = $_SERVER["HTTP_USER_AGENT"];
<p>You are using the <?php echo($browser);?> web browser.</p>
|Pages: 1 2 3 4||Next: Your first PHP script: Hello World! »|