Operating System
Programming Languages
Database
General
|
Php - Introduction
PHP is a powerful server-side scripting language for creating dynamic and interactive websites.html is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP. PHP is perfectly suited for Web development and can be embedded directly into the HTML code.The PHP syntax is very similar to Perl and C. PHP is often used together with Apache (web server) on various operating systems. It also supports ISAPI and can be used with Microsoft's IIS on Windows.
Why we Need PHP?
PHP is a server-side scripting language. This means that, although users will not need to install new software, the web host will need to have PHP set up on their server. It should be listed as part of the package
What can PHP do?
Anything. PHP is mainly focused on server-side scripting, so we can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more.
There are three main areas where PHP scripts are used.
- Server-side scripting.
This is the most traditional and main target field for PHP. You need threethings to make this work. The PHP parser (CGI or server module), a webserver and a web browser. They need to run the webserver, with a connected PHP installation.We can access the PHP program output with a web browser, viewing the PHP page through the server.
- Command line scripting.
This can make a PHP script to run it without any server or browser. This type of usage is ideal for scripts regularly executed using cron (on *nix or Linux) or Task Scheduler (on Windows). These scripts can also be used for simple text processing tasks.
- Writing desktop applications.
PHP is probably not the very best language to create a desktop application with a graphical user interface, but if you know PHP very well, and would like to use some advanced PHP features in your client-side applications you can also use PHP-GTK to write such programs.
PHP can be used on all major operating systems, including Linux, many Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, Mac OS X, RISC OS, and probably others. PHP has also support for most of the web servers today. This includes Apache, Microsoft Internet Information Server, Personal Web Server, Netscape and iPlanet servers, Oreilly Website Pro server, Caudium, Xitami, OmniHTTPd, and many others. For the majority of the servers PHP has a module, for the others supporting the CGI standard, PHP can work as a CGI processor.
Writing PHP
Writing PHP on the computer is actually very simple. We don't need any specail software, except for a text editor (like Notepad in Windows).
Declaring PHP
PHP scripts are always enclosed in between two PHP tags. This tells server to parse the information between them as PHP. The three different forms are as follows:
<?
PHP Code In Here
?>
<?php
PHP Code In Here
php?>
|
Variables
PHP allows you to define variables. In PHP there are several variable types, but the most common is called a String. It can hold text and numbers. All strings begin with a $ sign. To assign some text to a string you would use the following code:
$welcome_text = "Hello and welcome to my website.";
|
This is quite a simple line to understand, everything inside the quotation marks will be assigned to the string. Strings are case sensetive so $Welcome_Text is not the same as $welcome_text .String names can contain letters, numbers and underscores but cannot begin with a number or underscore .When assigning numbers to strings there is no neessary to include the quotes |