PHP Environment


In order to develop and run PHP Web pages three vital components need to be installed on your computer system.
  • Web Server - PHP will work with virtually all Web Server software, including Microsoft's Internet Information Server (IIS) but then most often used is freely available Apache Server. Download Apache for free here: http://httpd.apache.org/download.cgi
  • Database - PHP will work with virtually all database software, including Oracle and Sybase but most commonly used is freely available MySQL database. Download MySQL for free here: http://www.mysql.com/downloads/index.html
  • PHP Parser - In order to process PHP script instructions a parser must be installed to generate HTML output that can be sent to the Web Browser. This tutorial will guide you how to install PHP parser on your computer.
PHP Parser Installation:
Before you proceed it is important to make sure that you have proper environment setup on your machine to develop your web programs using PHP.
Type the following address into your browser's address box.
If this displays a page showing your PHP installation related information then it means you have PHP and Webserver installed properly. Otherwise you have to follow given procedure to install PHP on your computer.
This section will guide you to install and configure PHP over the following four platforms:
Apache Configuration:
If you are using Apache as a Web Server then this section will guide you to edit Apache Configuration Files.
PHP.INI File Configuration:
The PHP configuration file, php.ini, is the final and most immediate way to affect PHP's functionality.
Just Check it here: PHP.INI File Configuration
Windows IIS Configuration:
To configure IIS on your Windows machine you can refer your IIS Reference Manual shipped along with IIS.

How to get XML/HTML result set with mysql

you can get directly HTML,XML format of your resultset by just executing the query by following syntax.

uttam@uttam:~$ mysql -u[userName] -p -H -e "[query]" [database]

where -H is to get HTML resultset.you can replace this with -X to get XML output.
-e is to execute the query specified.

go to the shell promt. and thry this example.
mysql -uroot -p -H -e "select * from user" mysql




running perl script in apache

Perl script can be run as executable files in apache.All you have to do is to follow some basic steps given below.

open your apache.conf file in write mode and add the following line.by default it's under /etc/apache2/ directory.

AddHandler cgi-script .cgi .pl

save the file.

Next, search for the line that says " in the file. It should look something like this:[In this case /var/www/ is the document root.]


Options FollowSymLinks
AllowOverride None


Add "+ExecCGI" to the options list. The line now looks like this:
Options FollowSymLinks +ExecCGI

generally you can find this in sites-enabled/000-default file.

Restart your apache web server.

test by typing URL of your perl script in web browser.

ListContains

The ListContains function is a quick and easy function to use. The ListContains function determines the index of the first list element that contains the specified substring. If the substring can not be found in the list, The ListContains function will returns zero. This function will not ignore empty sets; thus the list "a,b,c,,,d" has 8 elements
 
The Function:
<php
function ListContains($list,$substring,$delimiter=",")
{
    $delimiter = substr($delimiter,1);
    $a = explode($list,$delimiter);
    $return = 0;
    for($i=0;$i< count($a);$i++)
    {
        if(strstr($a[$i],$substring))
        {
            $return = $i + 1;
        }
    }
    return $return;
}

?>
Usage:
Using the ListContains function is simple:
 
<?php
    $list = "one,two,three";
    $substr = "two" ; 
    if(ListContains($list,$substr) > 0)
    {
        echo $substr . " found at position " . ListContains($list,$substr):
    }
?>

The output of this function will be: two found at position 2

read a file in php

<?php

if(isset($_POST['filename']))
{
  if(!empty($_POST['filename']))
  {
    $file=$_POST['filename'].'.txt';
    if(file_exists($file))
    {
         $filename = fopen("$file", "r") ;
         while(!feof($filename))
               {
                 echo fgets($filename)."<br>";
               }
         fclose($filename);
    }
    else
    echo 'file not exits';
  }
 else
echo 'empty';

}
?>

<form action="file-read.php" method="POST">
<input type="text" name="filename">
.txt
<input type="submit" value="submit">
</form>

output :
1)enter the file name for read that file
2)that file must be text file

ex :        test.txt

ListDeleteAt

The ListDeleteAt function is a neat little coldfusion function and works just as well in PHP. This function is good for removing counted values from lists. I use it a lot in conjunction with other list functions.
The Function:

<php
function ListDeleteAt($list,$position,$delimiter)
{
$delimiter = substr($delimiter, 1);
$a = explode($delimiter,$list);
for($i=0;$i<count($a);$i++)

{
if($i != $position)
{
if(! isset($return))
{
$return = $a[$i];
}
else
{
$return .= $delimiter . $a[$i];
}
}
}
return $return;
}
?>

Usage:

To use the ListDeleteAt function with the default delimiter ',':

<php
$list = "a,b,c,d,e,f,g";

$position = 3;
echo ListDeleteAt($list,$position);
?>
The Result: a,b,d,e,f,g. The 'c' which was in the third position has noe been removed!

To use the ListDeleteAt function with a custom delimiter:

<php
$list = "12345";

$position = 2;
echo ListDeleteAt($list,$position);
?>

The Result: '1345'. The '2' which was in the second position has noe been removed!