Friday, May 20, 2011

NSString componentsSeparatedByCharactersInSet example objc

componentsSeparatedByCharactersInSet:

Returns an array containing substrings from the receiver that have been divided by characters in a given set.
- (NSArray *)componentsSeparatedByCharactersInSet:(NSCharacterSet *)separator
Parameters
separator
A character set containing the characters to to use to split the receiver. Must not be nil.
Return Value
An NSArray object containing substrings from the receiver that have been divided by characters in separator.
Discussion of componentsSeparatedByCharactersInSet
The substrings in the array appear in the order they did in the receiver. Adjacent occurrences of the separator characters produce empty strings in the result. Similarly, if the string begins or ends with separator characters, the first or last substring, respectively, is empty.

Example of [NSString componentsSeparatedByCharactersInSet

The method returns an array containing substrings from the receiver that have been divided by characters in a given set. [NSString componentsSeparatedByCharactersInSet] performs very simple lexical analysis internally to separate the string. See following code for real usage. 

NSString *str = @"A~B^C";
NSArray *arr = [str componentsSeparatedByCharactersInSet:
          [NSCharacterSet characterSetWithCharactersInString:@"^~"]];
NSLog(@"%@", arr);

Thursday, May 19, 2011

NSNumber initWithDouble example objc

You can create an NSNumber object with double value by calling NSNumber  initWithDouble method. NSNumber is an general container object for any number(integer, float, double...). Note that NSNumber initWithDouble method begins with "init" as its method prefix, so the returned object is not auto-released. You should release the NSNumber object when you are done with the object. [NSNumber initWithDouble example]

#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSNumber *objNum;
NSInteger n;
// create a NSNumber object with int value 100.
// it returns an autoreleased object. 
//
objNum = [NSNumber numberWithInt:100];
// Get the integer value from NSNumber.
//
n = [objNum integerValue];
NSLog(@"n:%i",n);
objNum = nil;
 
// allocate a number with Double value. not an autoreleased object.
//
objNum = [[NSNumber alloc]initWithDouble:0.7];
NSLog(@"number:%f", [objNum doubleValue]);
[objNum release];
[pool drain];
return 0; 
}

NSNumber integerValue example objc

You can extract the integer value from a NSNumber object by calling NSNumber:integerValue method. NSNumber is an general container object for any number(integer, float, double...). Note that NSNumber:integerValue method returns an integer value that is not an object but a native type value. NSInteger is just another name for 'int' type. [NSNumber:integerValue example]

Example>
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSNumber *objNum;
NSInteger n;
// create a NSNumber object with int value 100.
// it returns an autoreleased object. 
//
objNum = [NSNumber numberWithInt:100];
// Get the integer value from NSNumber.
//
n = [objNum integerValue];
NSLog(@"n:%i",n);
objNum = nil;
 
// allocate a number with Double value. not an autoreleased object.
//
objNum = [[NSNumber alloc]initWithDouble:0.7];
NSLog(@"number:%f", [objNum doubleValue]);
[objNum release];
[pool drain];
return 0; 
}

NSNumber numberWithInt example objc

You can create an NSNumber object with integer value by calling NSNumber numberWithInt method. NSNumber is an general container object for any number(integer, float, double...). Note that NSNumber numberWithInt method returns an autoreleased object. Unless the number is retained, it will go away after AutoReleasePool is drained. [NSNumber numberWithInt example]

#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSNumber *objNum;
NSInteger n;
// create a NSNumber object with int value 100.
// it returns an autoreleased object. 
//
objNum = [NSNumber numberWithInt:100];
// Get the integer value from NSNumber.
//
n = [objNum integerValue];
NSLog(@"n:%i",n);
objNum = nil;
 
// allocate a number with Double value. not an autoreleased object.
//
objNum = [[NSNumber alloc]initWithDouble:0.7];
NSLog(@"number:%f", [objNum doubleValue]);
[objNum release];
[pool drain];
return 0; 
}

SelectObject() example - Win32

SelectObject() is used to set some property to a device context(DC). SelectObject() changes the specified property and returns old property value ( that is replaced with the new one). Following example shows how to set a new Bitmap object to a DC using SelectObject() function. Note that old Bitmap object is returned and stored in hOldBMP variable.

        {
            // PNG Test code here!!!
            //
            PNGLoader      *pPNG = new PNGLoader("test.png");
            HDC                hDC = GetDC(hWnd);
            HDC                hMemDC = CreateCompatibleDC(hDC);
            HBITMAP         hOldBMP, hNewBMP;

            pPNG->read();
           
            // Display Image onto Screen for validation.
            //
            hNewBMP = CreateBitmap(pPNG->getWidth(), pPNG->getHeight(), 1, 32, pPNG->getBuffer());
            hOldBMP = (HBITMAP)SelectObject(hMemDC, hNewBMP);

            BitBlt(hDC, 0, 0, pPNG->getWidth(), pPNG->getHeight(), hMemDC, 0, 0, SRCCOPY);

            SelectObject(hMemDC, hOldBMP);
            DeleteObject(hNewBMP);
            DeleteDC(hMemDC);
            ReleaseDC(hWnd, hDC);
            delete pPNG;          
        }

NSArray objectAtIndex example objc

NSArray objectAtIndex returns the object at the specified index in the array. NSArray objectAtIndex is one of the most popular method used in iPhone SDK.
See following example.[NSArray objectAtIndex example]

Example>

{
      NSArray     *listData = [NSArray arrayWithObjects: @"MyName", @"YourName", @"HisName", nil];
      NSString    *textString;

textString = [listData objectAtIndex:1]; // "YourName".
}

NSArray arrayWithObjects example objc

An NSArray arrayWithObjects example is shown below. arrayWithObjects method returns a new NSArray object that contains pointer to the specified objects. The parameter list should end with "nil" to indiciate the end of the list. See following code [NSArray arrayWithObjects].

Example>
{
NSArray *KIA;
NSArray *SK;
NSArray *HD;
NSArray *LG;

KIA = [NSArray arrayWithObjects:@"Yun", @"Lee", @"LeeSB",@"Seo", @"Yang", nil];
SK = [NSArray arrayWithObjects:@"Kim", @"Koh", @"KimJ2",@"Jung", nil];
HD = [NSArray arrayWithObjects:@"Clock",@"Hwang", nil];
LG = [NSArray arrayWithObjects:@"Park", @"Bong", nil];

}

fseek() example c c++ objc

fseek() function sets the position indicator associated with the stream to a new position defined by adding offset to a reference position specified by origin. The End-of-File internal indicator of the stream is cleared after a call to this function, and all effects from previous calls to ungetc are dropped. When using fseek on text files with offset values other than zero or values retrieved with ftell, bear in mind that on some platforms some format transformations occur with text files which can lead to unexpected repositioning.
On streams open for update (read+write), a call to fseek allows to switch between reading and writing.

Declaration.
int fseek ( FILE * stream, long int offset, int origin );

Parameters

stream
Pointer to a FILE object that identifies the stream.
offset
Number of bytes to offset from origin.
origin
Position from where offset is added. It is specified by one of the following constants defined in <cstdio>:
SEEK_SETBeginning of file
SEEK_CURCurrent position of the file pointer
SEEK_ENDEnd of file

Return Value

If successful, the function returns a zero value.
Otherwise, it returns nonzero value.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
/* fseek example */
#include <stdio.h>

int main ()
{
  FILE * pFile;
  pFile = fopen ( "example.txt" , "w" );
  fputs ( "This is an apple." , pFile );
  fseek ( pFile , 9 , SEEK_SET );    // Go to 9th character of the file.
  fputs ( " sam" , pFile );          // This is an sample.
  fseek ( pFile , 0, SEEK_END);  // Go to end of the file.
  fputs ( " not end", pFile)         // This is an sample.not end
  fclose ( pFile );
  return 0;
}

fwrite() example c c++ objc

Following code shows a fwrite() example code. fwrite() is used to write a block of data into a file. The file must be open with fopen() before calling fwrite() function. In most cases, fwrite() is used to write into a binary file.[fwrite example]

Declaration.
size_t fwrite ( const void * ptr, size_t size, size_t count, FILE * stream );
 

Parameters
ptr
Pointer to the array of elements to be written.
size
Size in bytes of each element to be written.
count
Number of elements, each one with a size of size bytes.
stream
Pointer to a FILE object that specifies an output stream.

fwrite example)
FILE                *infile, *outfile;
int                 width = 800, height=600;
char                buf[32];


// Prepare data for buf[32]
//  ... Your code here


// Create a binary file.
outfile = fopen("mytest.dat", "wb");


fwrite(&width, 4, 1, outfile);
fwrite(&height, 4, 1, outfile);
fwrite(buf, 1, 32, outfile);
fclose(outfile);


// Read the binary file created above.
infile = fopen("mytest.dat", "rb");
fread(&width, 4, 1, infile);
fread(&height, 4, 1, infile);
fread(buf, 1, 32, infile);
fclose(infile);

fread() example c c++ objc

Following code shows a fread() example code. fread() is used to read a block of data from a file. The file must be open with fopen() before calling fread() function. In most cases, fread() is used to read a binary file.[fread example]

Declaration.
size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );

Parameters
ptr
Pointer to a block of memory with a minimum size of (size*count) bytes.
size
Size in bytes of each element to be read.
count
Number of elements, each one with a size of size bytes.
stream
Pointer to a FILE object that specifies an input stream.
 
fread example)
FILE                *infile, *outfile;
int                 width = 800, height=600;
char                buf[32];


// Prepare data for buf[32]
//  ... Your code here


// Create a binary file.
outfile = fopen("mytest.dat", "wb");


fwrite(&width, 4, 1, outfile);
fwrite(&height, 4, 1, outfile);
fwrite(buf, 1, 32, outfile);
fclose(outfile);


// Read the binary file created above.
infile = fopen("mytest.dat", "rb");
fread(&width, 4, 1, infile);
fread(&height, 4, 1, infile);
fread(buf, 1, 32, infile);
fclose(infile);

idct example c/c++ objc

Following "idct" code is collected from MPEG reference code. "idct" means inverse
discrete cosine transform. It basically converts time-domain data to
frequency domain data like FFT(fast fourier transform). idct algorithm is
very popular in Multimedia, Mobile Communication, Image Processing and so on.

-----------------------------------------------------------------

/* idct.c, inverse fast discrete cosine transform */

#include <config.h>
#include <stdio.h>
#include "mjpeg_types.h"
#include "transfrm_ref.h"

/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */

/*
* Disclaimer of Warranty
*
* These software programs are available to the user without any license fee or
* royalty on an "as is" basis. The MPEG Software Simulation Group disclaims
* any and all warranties, whether express, implied, or statuary, including any
* implied warranties or merchantability or of fitness for a particular
* purpose. In no event shall the copyright-holder be liable for any
* incidental, punitive, or consequential damages of any kind whatsoever
* arising from the use of these programs.
*
* This disclaimer of warranty extends to the user of these programs and user's
* customers, employees, agents, transferees, successors, and assigns.
*
* The MPEG Software Simulation Group does not represent or warrant that the
* programs furnished hereunder are free of infringement of any third-party
* patents.
*
* Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
* are subject to royalty fees to patent holders. Many of these patents are
* general enough such that they are unavoidable regardless of implementation
* design.
*
*/


/**********************************************************/
/* inverse two dimensional DCT, Chen-Wang algorithm */
/* (cf. IEEE ASSP-32, pp. 803-816, Aug. 1984) */
/* 32-bit integer arithmetic (8 bit coefficients) */
/* 11 mults, 29 adds per DCT */
/* sE, 18.8.91 */
/**********************************************************/
/* coefficients extended to 12 bit for IEEE1180-1990 */
/* compliance sE, 2.1.94 */
/**********************************************************/

/* this code assumes >> to be a two's-complement arithmetic */
/* right shift: (-2)>>1 == -1 , (-3)>>1 == -2 */



#define W1 2841 /* 2048*sqrt(2)*cos(1*pi/16) */
#define W2 2676 /* 2048*sqrt(2)*cos(2*pi/16) */
#define W3 2408 /* 2048*sqrt(2)*cos(3*pi/16) */
#define W5 1609 /* 2048*sqrt(2)*cos(5*pi/16) */
#define W6 1108 /* 2048*sqrt(2)*cos(6*pi/16) */
#define W7 565 /* 2048*sqrt(2)*cos(7*pi/16) */

/* global declarations */

/* private data */
static int16_t iclip[1024]; /* clipping table */
static int16_t *iclp;

/* private prototypes */
static void idctrow (int16_t *blk);
static void idctcol (int16_t *blk);

/* row (horizontal) IDCT
*
* 7 pi 1
* dst[k] = sum c[l] * src[l] * cos( -- * ( k + - ) * l )
* l=0 8 2
*
* where: c[0] = 128
* c[1..7] = 128*sqrt(2)
*/


static void idctrow(int16_t *blk)
{
int x0, x1, x2, x3, x4, x5, x6, x7, x8;

/* int16_tcut */
if (!((x1 = blk[4]<<11) | (x2 = blk[6]) | (x3 = blk[2]) |
(x4 = blk[1]) | (x5 = blk[7]) | (x6 = blk[5]) | (x7 = blk[3])))
{
blk[0]=blk[1]=blk[2]=blk[3]=blk[4]=blk[5]=blk[6]=blk[7]=blk[0]<<3;
return;
}

x0 = (blk[0]<<11) + 128; /* for proper rounding in the fourth stage */

/* first stage */
x8 = W7*(x4+x5);
x4 = x8 + (W1-W7)*x4;
x5 = x8 - (W1+W7)*x5;
x8 = W3*(x6+x7);
x6 = x8 - (W3-W5)*x6;
x7 = x8 - (W3+W5)*x7;

/* second stage */
x8 = x0 + x1;
x0 -= x1;
x1 = W6*(x3+x2);
x2 = x1 - (W2+W6)*x2;
x3 = x1 + (W2-W6)*x3;
x1 = x4 + x6;
x4 -= x6;
x6 = x5 + x7;
x5 -= x7;

/* third stage */
x7 = x8 + x3;
x8 -= x3;
x3 = x0 + x2;
x0 -= x2;
x2 = (181*(x4+x5)+128)>>8;
x4 = (181*(x4-x5)+128)>>8;

/* fourth stage */
blk[0] = (x7+x1)>>8;
blk[1] = (x3+x2)>>8;
blk[2] = (x0+x4)>>8;
blk[3] = (x8+x6)>>8;
blk[4] = (x8-x6)>>8;
blk[5] = (x0-x4)>>8;
blk[6] = (x3-x2)>>8;
blk[7] = (x7-x1)>>8;
}

/* column (vertical) IDCT
*
* 7 pi 1
* dst[8*k] = sum c[l] * src[8*l] * cos( -- * ( k + - ) * l )
* l=0 8 2
*
* where: c[0] = 1/1024
* c[1..7] = (1/1024)*sqrt(2)
*/

static void idctcol(int16_t *blk)
{
int x0, x1, x2, x3, x4, x5, x6, x7, x8;

/* int16_tcut */
if (!((x1 = (blk[8*4]<<8)) | (x2 = blk[8*6]) | (x3 = blk[8*2]) |
(x4 = blk[8*1]) | (x5 = blk[8*7]) | (x6 = blk[8*5]) | (x7 = blk[8*3])))
{
blk[8*0]=blk[8*1]=blk[8*2]=blk[8*3]=blk[8*4]=blk[8*5]=blk[8*6]=blk[8*7]=
iclp[(blk[8*0]+32)>>6];
return;
}

x0 = (blk[8*0]<<8) + 8192;

/* first stage */
x8 = W7*(x4+x5) + 4;
x4 = (x8+(W1-W7)*x4)>>3;
x5 = (x8-(W1+W7)*x5)>>3;
x8 = W3*(x6+x7) + 4;
x6 = (x8-(W3-W5)*x6)>>3;
x7 = (x8-(W3+W5)*x7)>>3;

/* second stage */
x8 = x0 + x1;
x0 -= x1;
x1 = W6*(x3+x2) + 4;
x2 = (x1-(W2+W6)*x2)>>3;
x3 = (x1+(W2-W6)*x3)>>3;
x1 = x4 + x6;
x4 -= x6;
x6 = x5 + x7;
x5 -= x7;

/* third stage */
x7 = x8 + x3;
x8 -= x3;
x3 = x0 + x2;
x0 -= x2;
x2 = (181*(x4+x5)+128)>>8;
x4 = (181*(x4-x5)+128)>>8;

/* fourth stage */
blk[8*0] = iclp[(x7+x1)>>14];
blk[8*1] = iclp[(x3+x2)>>14];
blk[8*2] = iclp[(x0+x4)>>14];
blk[8*3] = iclp[(x8+x6)>>14];
blk[8*4] = iclp[(x8-x6)>>14];
blk[8*5] = iclp[(x0-x4)>>14];
blk[8*6] = iclp[(x3-x2)>>14];
blk[8*7] = iclp[(x7-x1)>>14];
}

/* two dimensional inverse discrete cosine transform */
void idct(int16_t *block)
{
int i;

for (i=0; i<8; i++)
idctrow(block+8*i);

for (i=0; i<8; i++)
idctcol(block+i);
}

void init_idct(void)
{
int i;

iclp = iclip+512;
for (i= -512; i<512; i++)
iclp[i] = (i<-256) ? -256 : ((i>255) ? 255 : i);
}

understanding LAMP architecture

December 1, 2005
Understanding LAMP
By Martin Brown



If you're at all familiar with open source software, chances are you've heard the phrase "LAMP stack" at some point. You may even know what it stands for. But do you know what LAMP actually is?
The simple answer is LAMP is a Web application development and deployment environment that, although powerful, is also comparatively simple and easy to use. This article will explain what LAMP is, the different components of the LAMP environment, and how, when combined, they create such a powerful environment. We will also look at how LAMP technology can drive Web applications.

Exploding the Acronym

Simply exploding the acronym on a letter by letter basis gives us the following elements:
  • Linux
  • Apache Web server
  • MySQL database
  • Perl, Python, or PHP
Individually, each of these items is a powerful component in its own right. The key to the idea behind LAMP, a term originally coined by Michael Kunze in the German magazine c't in 1998, is the use of these items together. Although not actually designed to work together, these open source software alternatives are readily and freely available. This has lead to them often being used together. In the past few years, their compatibility and use together has grown and been extended. Certain extensions have even been created specifically to improve the cooperation between different components.
Today, the products that make up the LAMP stack are included by default in nearly all Linux distributions, and together they make a powerful web application platform. Figure 1 illiustrates the relationship between the components.
Figure 1
LAMP Relationships

LAMP Relationships

Each of the components in the LAMP stack is an example of Free or Open Source Software (FOSS). The benefit of the FOSS approach is three-fold. First, the nature of FOSS software means applications are available for free download, making them readily available to a wide range of people without payment. That makes the software incredibly attractive to a wide range of users who would otherwise have to pay for "professional" commercial tools, which is often an expensive step in producing a Web site.
Second, FOSS licenses are open and thus have few restrictions on their use and deployment of applications based on the FOSS technology. It is possible to develop and deploy LAMP-based projects without paying any license fees for distributing the software, and this, again, makes it popular for both hobbyists and professionals alike.
Third, and a major reason for the growth and use of FOSS technology (including LAMP), is that because users have access to the source it is much easier to fix faults and improve the applications. In combination with the open license, this simplifies the development process for many enterprises and gives them flexibility that simply isn't available within the confines of a proprietary or commercial-based product.

Linux
Linux is the operating system on which the applications execute. As an operating system, Linux is obviously capable of acting as much more than a Web application platform, but it has many benefits in this space. Aside from the FOSS approach of Linux, the flexibility of the Linux operating system and how it can be customized means it is fairly easy to produce a highly optimized platform on which to deploy Web applications.
For example, Linux supports a range of different file systems, some of which make more sense for Web serving than otehrs. We can also heavily customize the Linux kernel to tweak the best performance, and years of open source development have produced a wide range of network drivers.
The open source approach of Linux has meant that the operating system has been developed for a wide range of platforms, from desktop PCs to massive servers and mainframe hardware, all the way down to embedded systems. Thus, "old" or unusual hardware that is no longer OEM-supported can now be used to run Linux and to deploy LAMP applications.
Despite all the complexities of the Linux operating system, the distribution model, which packages together different components, means installation and deployment of Linux-based server can be very easy. There are even distributions specially designed to be used when developing and deploying LAMP-based applications, further simplifying the use of LAMP technology.
Apache HTTPD
The Apache project is now a generic name given to a number of high-quality, open-source-based application projects, but its original project was the HTTPD Web server. Apache HTTPD is a powerful Web serving platform that can be used to provide basic file-based serving, which can work with CGI to provide interactive applications or be combined with loadable modules to support a very efficient Web application service.
Apache HTTPD itself is a relatively simple product but a very fast and capable one. Although this description may be seen as slightly unfair considering the flexibility and functionality of the application, the real power of the Apache HTTPD server is its support for loadable extension modules to enhance that base functionality.
Within the standard Apache HTTPD project, these include modules for caching data, providing different authentication and security environments, and supporting a wide range of management functionality, such as Web site traffic. For Web application support, modules enhance the power of the Apache HTTPD by allowing users to embed an interpreter for one of the LAMP languages (Perl, Python, or PHP) into the Apache HTTPD project, significantly increasing the speed with which these applications are executed and therefore improving the responsiveness of the Web application.
Although complex at first, Apache can be easily installed and configured and then largely forgotten about. It is safe, secure, and self-managing, and it needs little attention to keep it running. In general, once the initial configuration has been completed, an Apache installation need never be touched ever again.

MySQL
The MySQL Relational Database Management System (RDBMS) is another example of a simple but very powerful application. As is the case with Linux and Apache, you can generally install a MySQL server and start using it without having to go through any complex configuration or optimization procedures. In its default configuration, MySQL is a very capable relational database, but serious users can also tweak the settings to gain better performance, functionality, or both, simply by changing the underlying storage engine. The article, MySQL Storage Engines, on LinuxPlanet, discusses the various storage engines available.
Figure 2
MySQL in Action

MySQL in Action
The power of MySQL is that it supports SQL and relational tables, making it much easier to develop enterprise-level databases while using the standard SQL language. Enterprise with small and large databases alike use MySQL. It is particularly efficient with applications that have a comparatively large number of queries and few updates (particularly in its default configuration), and it is therefore well-placed to support dynamic and database-driven apps, such as blogs, stores, and reference databases.
Applications with a high number of transactions use the InnoDB storage engine that is designed to handle the higher level of transactions and does not impose the same locking restrictions that can affect other storage engine types.
Perl, Python, or PHP
The main benefit of all three of the languages in the LAMP stack, Perl, Python and PHP, is that they are "interpreted" languages. Being interpreted, rather than compiled, they are quick and easy to use. There is no need for the application you are writing to be compiled — you just run the application. This speeds up development time and makes it easier to use and learn languages. They all provide a rich environment that makes it easy to perform complex tasks and provide an interface for developers to extend that functionality. When combined, they each make a powerful, but simple, environment for writing applications of all kinds.
Perl, Python, and PHP were originally heavily used during Web development because of the CGI interface built into early Web servers (Apache included, of course). CGI enables the Web server to exchange data between the client's browser and an external application in a defined way. By supporting external, CGI-based applications, Web developers could introduce dynamic elements. Developing compiled applications that used this interface was comparatively complex, but the interpreted languages usually include the functionality, either directly (as with PHP) or through a standard module (as with Perl and Python).
The early Web pioneers mostly used Perl, a flexible language, particularly when dealing with text elements, which made it easy to process the data supplied through the CGI interface and also to manipulate text files and simple databases to support the dynamic elements. The integration of Perl as a dynamic language is further extended through the mod_perl module for Apache. The mod_perl module, among other techniques, embeds the Perl interpreter into the Apache installation, enabling the execution of Perl scripts without the significant overhead that occurs with CGI.
PHP, or Personal Home Pages, was originally a suite of Perl scripts that used the CGI interface to create a dynamic home page for Rasmus Lerdorf. When the PHP environment took off, the language was completely redeveloped as a stand-alone programming language, but it still owes much of the language semantics to the Perl language on which it was based. Where PHP has the edge on Perl is that PHP is a language designed to develop Web applications and is therefore much more logical in use for some programmers. Furthermore, because the PHP code is directly embedded into Web pages, the way the language works and interacts with the HTML is clearer and easier to understand, even for non-programmers. PHP is also often easier to be deployed to a hosting service because you need only supply the PHP pages, not a combination of HTML pages and CGI scripts.

LAMP Is Greater Than the Sum of Its Parts
The Apache server running on Linux is an easy way of building a simple Web server, but the information provided by the Apache server will be "static" — that is, basic pages of information that the you must build and type yourself.
Adding interactive or dynamic components requires the use of a programming language, like Perl or PHP. These allow you to work with forms. For example, they let your users send you an e-mail or randomly select a page to visit.
By combining a Web server (Apache), dynamic components (using Perl, Python, or PHP), and a database (MySQL) we can create a truly database-driven and dynamic Web site that is easy to update and provides rich functionality to support users.
For truly interactive and dynamic Web sites, however, what you need is a way of building pages composed of information in a database. For example, imagine you want to create an online store along the lines of Amazon. You could do it using static pages. You could even use dynamic elements to let people add products to their basket and send their order to you, but as the number of products to be sold increases, the management overhead to control everything will become a nightmare. Furthermore, providing advanced functionality for customers, such as the ability to view past orders, can be impossible.
This is where the power of the LAMP stack shines. By combining a Web server (Apache), dynamic components (using Perl, Python or PHP), and a database (MySQL) we can create a truly database-driven and dynamic Web site that is easy to update and provides rich functionality to support users.
The easiest way to see the power and functionality of the LAMP stack in action is to take a look at some of the pre-packaged applications available that use LAMP technology. A well-known example of this is the WordPress blogging system. WordPress uses PHP to interface with a MySQL database and can be hosted on an Apache/Linux server.
Choosing to use open source for your business is not about cost; it is about the effectiveness and capabilities of the product to do its job.
The WordPress system is powerful and demonstrates most of the functionality of the LAMP system. PHP is the application environment, extracting data from the database and formatting it for display in a Web browser. All of the "articles" or posts are stored in a MySQL database, and individual posts are categorized in the right-hand panel to make it easy to find and locate posts on specific topics. Posts can also be selected by date, and even author, since WordPress also supports multiple users. WordPress can use the relational functionality of MySQL to display posts ordered by category or to display only specific categories. Even in the simple display of the "home" page, it uses the relational features of MySQL to extract relevant data for each post.
Another good example is Wikipedia, which uses PHP, MySQL, and Apache HTTPD to provide an online encyclopedia with thousands of entries in multiple languages. All of this is served by Linux servers running the WikiMedia application.
Figure 3
Wikipedia at Work

Wikipedia at Work
This functionality is possible within other Web application environments, but the key is how simply all of the LAMP components work together. The WordPress code, for example, is surprisingly simple and straightforward. The code is easily customized and extended, and formatting can be altered to meet individual needs. 

Using the LAMP Stack in Your Business
Choosing to use LAMP in your business is not about cost — although many enterprsies will be attracted to the low-cost required for both development and deployment. Instead, choosing LAMP for your organization is about the benefits it provides, as summarized below.
  • Flexibility: There are no limits to what you can do with the LAMP stack, either technically or because of licensing restrictions. This allows you the flexibility to build and deploy applications in a method that suits you, not the supplier of the technology you are using.
  • Customization: Because LAMP components are open source, they have built up a huge array of additional components and modules that provide additional functionality. The open source approach enables you to do the same, customizing components and functionality to suit your needs.
  • Ease of Development: You can write powerful applications using LAMP technology in relatively few lines of code. Often the code is straightforward enough that even nonprogrammers can modify or extend the application.
  • Ease of Deployment: With neither licensing issues nor the need to compile applications, deployment is often as easy as copying an application to a new host. Most hosting services provide LAMP-based environments as standard, or they can be deployed using a Linux distribution, such as Fedora or Debian.
  • Security: With many eyes developing the software and years of use by a wide range of users and community groups, LAMP technology is secure and stable. Problems are normally fixed very quickly, and without the need for a costly support contract.
  • Community and Support: A wide and experienced group of people is willing to provide help and support during the development and deployment of LAMP-based applications.
Many successful business have already leveraged the use of LAMP technology. Many heavily trafficked Web sites use LAMP, or components of it, to support their applications.
Related Acronyms
The original LAMP acronym has spawned a number of other, related acronyms that capitalize on the main focus of the original combination of technologies to provide feature rich Web sites. Although many alternatives are out there, the most prominent are the following:
·  LAPP - Linux, Apache, PostGreSQL, Perl/Python/PHP
·  WAMP - Windows, Apache, MySQL, Perl/Python/PHP
·  MAMP - Macintosh, Apache, MySQL, Perl/Python/PHP
·  BAMP - BSD, Apache, MySQL, Perl/Python/PHP
·  WIMP - Windows, IIS, MySQL, Perl/Python/PHP
·  AMP - Which allows the omission of the operating system
They are all based around similar principles, with the most common item being the languages. To be fair, the operating system is not as important as the server, database, and language options, since AMP is also an effective combination on other platforms, including Windows. It is, however, more common to use an entirely open source solution, and the support that comes with Linux distributions for easily installable versions is an obvious bonus.
Conclusions
The LAMP stack is basically the combination of four popular open source technologies that together produce a powerful application serving platform. LAMP is often seen as the best open source solution to compete with proprietary and commercial products, such as Windows, IIS, and .NET. Certainly its low cost is appealing, but the open source nature, making for free and easy development and deployment, is a much more attractive reason to use the technology. Choosing to use it for your business is not about cost; it is about the effectiveness and capabilities of the product to do its job.