Skip to main content

www.php.net online manual user notes contributions

Sometime ago I had lot of interest in contributing to the www.php.net 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:

http://www.php.net/ref.pdf#32797
Date: 7 Jun 2003 06:42:11 -0000

If you want to create PDF without using PDFlib library, you may try FPDF ( http://www.fpdf.org ).

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. ( http://www.phpmyadmin.net )


http://www.php.net/ref.array#32969
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)
unset($arr[$key]);
return( $arr );

}/*---------RemoveArrayElement()----------*/



Example:


$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




http://www.php.net/uniqid#33113
Date: 17 Jun 2003 07:21:58 -0000

A nice article/code for creating auto-password with uniqid is at http://www.phpbuddy.com/article.php?id=25


http://www.php.net/date#33251
Date: 20 Jun 2003 05:14:08 -0000

A very nice class to play with dates is available at http://www.phpinsider.com/php/code/Date_Calc/

You can look at it's application at http://www.phpinsider.com/php/code/Date_Calc/showCalendarMonth.php


http://www.php.net/date#33252
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.


http://www.php.net/ref.mail#35384
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 127.0.0.1 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 ( http://www.argosoft.com/applications/mailserver/ )

Step1:
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 127.0.0.1
5. Start (run) the ArGoSoft Mail Server and make sure there is no error.
6. Now, the "localhost" (127.0.0.1) is your SMTP & POP3 server.

Step2:
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.


http://www.php.net/getenv#35496
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.]


<?php

//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 = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
return($ip);
}/*-------GetIP()-------*/

?>




http://www.php.net/fgetcsv#35602
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).


http://www.php.net/header#35667
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')


http://www.php.net/explode#37004
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.



<?php

//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;
++$i;
} else if ($str[$i] == $qual) {
$inside = !$inside;
} else {
$word .= $str[$i];
}
}
$out[] = $word;
return $out;

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

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

?>




http://www.php.net/ref.sqlite#37243
Date: 7 Nov 2003 12:19:21 -0000

Very nice MS PowerPoint presentation titled "SQLite and PHP" (author: Wez Furlong) can be downloaded at http://www.php.net/~wez/SQLite_and_PHP.ppt [134 KB]


http://www.php.net/ref.pfpro#38301
Date: 16-Dec-2003 04:49

Zend has a nice tutorial titled "Accepting payments using Verisign's Payflow Pro" at http://www.zend.com/zend/tut/tutorial-staub.php


http://www.php.net/ref.pfpro#38302
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.


http://www.php.net/getmxrr#40236
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.


<?php
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

//test..
echo getmxrr('yahoo.com', $mxhosts);
print_r($mxhosts);
?>




http://www.php.net/ref.sdo#63280
Date: 18-Mar-2006 01:07

Some useful links on SDO:
1. Quick intro ( http://www.obalweb.net/wppro/?p=19 )
2. SDO for Zend Conf 2005 ( http://www.ibm.com/developerworks/forums/weblogs/data/SDOforZendConf2005.pdf ), Presentation, [481 KB], Graham Charters, 2005-10-18
3. Introducing Service Data Objects for PHP ( http://www.zend.com/pecl/tutorials/sdo.php ), 2005-08-05
4. Service Data Objects specification ( http://www.ibm.com/developerworks/library/specification/j-commonj-sdowmt/ ), 2003-2005


http://www.php.net/iconv#43463
Date: 22-Jun-2004 08:40
Here is a code to convert ISO 8859-1 to UTF-8 and vice versa without using iconv.


<?php
//Logic from http://twiki.org/cgi-bin/view/Codev/InternationalisationUTF8
$str_iso8859_1 = 'foo in ISO 8859-1';
//ISO 8859-1 to UTF-8
$str_utf8 = preg_replace("/([\x80-\xFF])/e",
"chr(0xC0|ord('\\1')>>6).chr(0x80|ord('\\1')&0x3F)",
$str_iso8859_1);
//UTF-8 to ISO 8859-1
$str_iso8859_1 = preg_replace("/([\xC2\xC3])([\x80-\xBF])/e",
"chr(ord('\\1')<<6&0xC0|ord('\\2')&0x3F)",
$str_utf8);
?>




http://www.php.net/ord#46267
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).


<?php
/**
* @Algorithm: http://www1.tip.nl/~t876506/utf8tbl.html
* @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;
}

//debug
echo uniord('A'); //65
echo uniord("\xe0\xae\xb4"); //2996
?>




http://www.php.net/getrusage#47467
Date: 17-Nov-2004 10:51

Here is a nice comment on benchmarking PHP codes using getrusage function http://blog.rompe.org/node/85


http://www.php.net/output_add_rewrite_var#53966
Date: 19-Jun-2005 02:41

This function obeys url_rewriter.tags ( http://www.php.net/ref.session#ini.url-rewriter.tags ) configuration and hence can be used to rewrite selected tags.


http://www.php.net/ref.session#53965
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 http://bugs.php.net/13472

Comments

Popular posts from this blog

Valen Smith, the English teacher videos are missing!

I vaguely remembered that sometimes around 2009, engVid on YouTube was very popular. I especially liked a teacher by name Valen Smith's videos. She was not only beautiful but also very good at explaining the English usage. I also vaguely remembered to check her channel ValenESL around 2015. But, not sure what happened to her or engVid, all her videos are sadly gone. I have also noted that many people on Twitter were asking the same. Not sure what happened. Some people seem to have reuploaded her videos and YouTube continuously removing them with a note "This video contains content from LearnVid, who has blocked it on copyright grounds." Strangely though, on Facebook, some people have managed to create a fake account using her old channel name ValenESL.

Malayalis may not have valued Nedumudi Venu, but ChatGPT did

Back in the late 1980s (exactly in 1988, according to some searches)—there was a much-loved Malayalam serial called Mandan Kunju . Ever since then, our family developed a deep appreciation for Nedumudi Venu. His acting was often compared to that of Sivaji Ganesan, who was widely celebrated at the time. There were even debates about how Nedumudi was surpassing Sivaji with his unmatched natural style. Even in his 30s, Nedumudi would appear with grey hair, convincingly portraying elderly characters. About 35 years ago, I happened to watch a film in which Nedumudi Venu actually played the lead role—something quite rare in his career. I couldn’t remember the plot or the supporting cast, but what stayed with me vividly was the setting. The film had been shot in Munnar’s Madupetty Estate, with the estate school serving as one of the locations. I also remembered a Carnatic-influenced song filmed outdoors in the estate, which left a strong impression on me. For years, I tried to rediscover ...

Looking Back at My Predictions

People who work closely with me often appreciate my ability to anticipate trends in technology stacks. With that in mind, I recently revisited some of my old blog posts—and it turns out, many of those predictions have held true. Here are a few handpicked posts that aged well: Prediction: Expensify will crash through its insane question-based hiring process February 23, 2022 BlackLivesMatter campaign may consolidate votes for Trump June 15, 2020 Technology prediction for 2018 January 16, 2018 Node.js and client app are the future of webdeving? December 29, 2011 Yahoo! and delicious.com - What's wrong? December 19, 2010 Disclosure: The following ChatGPT prompt is used in this blog post: Please fix the language of the below text and highlight the changes in bold: