Saturday, August 16, 2008 online manual user notes contributions

Sometime ago I had lot of interest in contributing to the online manual's notes. Thought lot of them are deleted now and not even relevant now, I'd thought of archiving them for my own reference:
Date: 7 Jun 2003 06:42:11 -0000

If you want to create PDF without using PDFlib library, you may try FPDF ( ).

If you want to know, how to use FPDF in PHP scripts, you can look at the source code of phpMyAdmin as phyMyAdmin uses this FPDF. ( )
Date: 12 Jun 2003 11:32:58 -0000

If you want to remove a particular element from the array without loosing the keys, you can use the following function:

function RemoveArrayElement($arr, $element)
if (($key=array_search($element, $arr))!==false)
return( $arr );



$arr = array("a","b","c","f","x","d","e","z","l");
print_r($arr); //debug
$arr = RemoveArrayElement($arr, "a");
print_r($arr); //removes the "a"
$arr = RemoveArrayElement($arr, "xxx");
print_r($arr); //no match of "xxx"; so displays the original array
Date: 17 Jun 2003 07:21:58 -0000

A nice article/code for creating auto-password with uniqid is at
Date: 20 Jun 2003 05:14:08 -0000

A very nice class to play with dates is available at

You can look at it's application at
Date: 20 Jun 2003 05:35:33 -0000

If you want to just compare any two dates, store them in ISO format (yyyy-mm-dd) and compare with < or > or == operators.

For example, $date1 = "2003-12-30"; $date2 = "2004-02-15";

if ($date1 < $date2) echo "date1 is less than date2";

Note, $date1 & $date2 are just strings. You can use this logic in MySQL too.
Date: 29 Aug 2003 10:20:47 -0000

[Recently realized a flaw in my previous note related to sending mail using ArGoSoft Mail Server. Only the IP should be used to relay, otherwise others may anonymously send spam mails using that IP. So, here is the improved note about the stuff]

For Windows users who work on local machine:

If you want to send emails from your local machine you can try ArGoSoft Mail Server ( )

1. Install ArGoSoft Mail Server
2. Open the ArGoSoft Mail Server and click Tools > Options to configure.
3. Enter the DNS server name or let the ArGoSoft Mail Server to auto-detect.
4. In the IP Homes tab, enter
5. Start (run) the ArGoSoft Mail Server and make sure there is no error.
6. Now, the "localhost" ( is your SMTP & POP3 server.

1. Open your php.ini
2. Enter the value of SMTP like SMTP = localhost

That's all!

Do not trust "sendmail_from" of php.ini. Always set headers parameter in mail() function.
Date: 3 Sep 2003 08:04:27 -0000

[Worked depending upon the comment of "hanez at forpresident dot com". Reviewed Anders Winther and "Joenema at aol dot com"'s "bullet-proof" IP address fetcher and came out with a new tight code.]


//Get the real client IP ("bullet-proof"???)

function GetIP()
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = "unknown";

Date: 08-Sep-2003 03:32

Important note about the CSV format:
There should *not* be any space in between the fields. For example,
field1, field2, field3 [Wrong!]
field1,field2,field3 [Correct-No space between fields]

If you add space between the fields, MS Excel won't recognize the fields (especially date and multi-line text fields).
Date: 10 Sep 2003 12:15:03 -0000

Since IE 5.5, IE has a typical bug called "IE title refresh bug". If the connection is broken while browsing certain sites, IE will show "Cannot find server" page and the title will remain "Cannot find server" even if the page is get loaded after the connection is established. AFAIK, there is no fix for this bug.

I have recently found that Google's pages don't have this problem; Google uses header('Cache-control: private')
Date: 30 Oct 2003 12:03:12 -0000

The improved CSV Explode function of "hhromic at udec dot cl" again has one limitation with MS Excel.

His version returns "" for """". But the expected result is " for """"

And so, I have modified his code with additional inside check.


//Explode CSV (MS Excel) string

function csv_explode($str, $delim = ',', $qual = "\"")
$len = strlen($str);
$inside = false;
$word = '';
for ($i = 0; $i < $len; ++$i) {
if ($str[$i]==$delim && !$inside) {
$out[] = $word;
$word = '';
} else if ($inside && $str[$i]==$qual && ($i<$len && $str[$i+1]==$qual)) {
$word .= $qual;
} else if ($str[$i] == $qual) {
$inside = !$inside;
} else {
$word .= $str[$i];
$out[] = $word;
return $out;

} /*-------csv_explode()------------*/

$csv_str = 'a,"""","""",d,e,f';
print_r( csv_explode($csv_str) );

Date: 7 Nov 2003 12:19:21 -0000

Very nice MS PowerPoint presentation titled "SQLite and PHP" (author: Wez Furlong) can be downloaded at [134 KB]
Date: 16-Dec-2003 04:49

Zend has a nice tutorial titled "Accepting payments using Verisign's Payflow Pro" at
Date: 16 Dec 2003 06:56:22 -0000

This is just a comment on the note by "jason at thinkingman dot org". His note should be better modified to give the idea that it's a workaround for Win32 Platforms. Also, the Editor's link is missing.
Date: 26-Feb-2004 04:41

Here is a better workaround for Windows platform. Tested on Windows XP. Highly impressed by "geoffbrisbine A T y a h o o DOT c o m"'s idea of nslookup usage.

function getmxrr($hostname, &$mxhosts)
$mxhosts = array();
exec('nslookup -type=mx '.$hostname, $result_arr);
foreach($result_arr as $line)
if (preg_match("/.*mail exchanger = (.*)/", $line, $matches))
$mxhosts[] = $matches[1];
return( count($mxhosts) > 0 );
}//--End of workaround

echo getmxrr('', $mxhosts);
Date: 18-Mar-2006 01:07

Some useful links on SDO:
1. Quick intro ( )
2. SDO for Zend Conf 2005 ( ), Presentation, [481 KB], Graham Charters, 2005-10-18
3. Introducing Service Data Objects for PHP ( ), 2005-08-05
4. Service Data Objects specification ( ), 2003-2005
Date: 22-Jun-2004 08:40
Here is a code to convert ISO 8859-1 to UTF-8 and vice versa without using iconv.

//Logic from
$str_iso8859_1 = 'foo in ISO 8859-1';
//ISO 8859-1 to UTF-8
$str_utf8 = preg_replace("/([\x80-\xFF])/e",
//UTF-8 to ISO 8859-1
$str_iso8859_1 = preg_replace("/([\xC2\xC3])([\x80-\xBF])/e",
Date: 05-Oct-2004 08:01

[Fixed a bug in my previous note; ord() is missing in first condition]

uniord() function like "v0rbiz at yahoo dot com" (Note# 42778), but without using mbstring extension. Note: If the passed character is not valid, it may throw "Uninitialized string offset" notice (may set the error reporting to 0).

* @Algorithm:
* @Logic: UTF-8 to Unicode conversion
function uniord($c)
$ud = 0;
if (ord($c{0})>=0 && ord($c{0})<=127)
$ud = ord($c{0});
if (ord($c{0})>=192 && ord($c{0})<=223)
$ud = (ord($c{0})-192)*64 + (ord($c{1})-128);
if (ord($c{0})>=224 && ord($c{0})<=239)
$ud = (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128);
if (ord($c{0})>=240 && ord($c{0})<=247)
$ud = (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128);
if (ord($c{0})>=248 && ord($c{0})<=251)
$ud = (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128);
if (ord($c{0})>=252 && ord($c{0})<=253)
$ud = (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128);
if (ord($c{0})>=254 && ord($c{0})<=255) //error
$ud = false;
return $ud;

echo uniord('A'); //65
echo uniord("\xe0\xae\xb4"); //2996
Date: 17-Nov-2004 10:51

Here is a nice comment on benchmarking PHP codes using getrusage function
Date: 19-Jun-2005 02:41

This function obeys url_rewriter.tags ( ) configuration and hence can be used to rewrite selected tags.
Date: 19-Jun-2005 03:37

The note regarding url_rewriter.tags and XHTML conformity in the manual is bit confusing; it's applicable only when we use <fieldset> tags. Refer

No comments: