Archive for November, 2008

Installing PHP 5 and apache on windows xp

PHP is best suited for LAMP [Linux, Apache, MySQL and PHP] environment, but we can use in WAMP [Windows, Apache, MySQL and PHP] environment also, here are the options to install & configure php with apache in windows machines.
1] Use WAMP Server or XAMPP server for one click installation, no need for configuration.
2] Manually install [...]

Recursive function in PHP

recursive function is a function that calls itself repeatedly for a specified condition.
Here is an example function which calls itself to perform a tree structure for a category table
Here is the category table:

category_id
parent_id
category_name

1
0
CMS

2
0
Blogs

3
0
Forums

4
0
E-Commerce

5
1
Joomla

6
1
Mambo

7
6
Templates

8
6
Mods/Components

9
4
OSCommerce

10
2
Wordpress

11
10
Themes

12
10
Plugins

<?php
echo ‘<select name=”category”>
<option value=”0″>Root</option>’;

$allcats = getTree();

foreach($allcats as $key=>$value)
{
echo “<option value=’$key’>$value</option>”;
}
echo ‘</select>’;

foreach($allcats as $key=&gt;$value)
{
echo “$value”;
}
echo ‘

‘;

function getTree($id=0)
{
static $cates = array();
static $times = 0;
$times++;
$result = [...]

Email validation using PHP regular expression

Regular expression is a wonderful concept, using this we can play with strings in PHP. The practical use of regular expression is:

Email validation
validating domain name
validating post code format etc.

There are two types of regular expression functions:

ereg functions or POSIX extended regular expression function, which is the standard functions for PHP
preg functions or perl Compatible regular [...]