Sunday, January 8, 2012

New blog!

Check out my new blog at http://blog.luksidadi.com

Ill be focusing more on the new technologies such as node.js, socket.io, backbone.js, etc

Monday, April 4, 2011

Domain Names Validation - IDN Validation - Domain Names Validator - IDN Validator - TLD Validation - TLD Validator

You can find the source codes here:
https://github.com/aluksidadi/IDN-Validator
or
https://sourceforge.net/projects/idnvalidator/

Domain Names Validation - IDN Validation - Domain Names Validator - IDN Validator - TLD Validation - TLD Validator

This class is a class to validate various domain names including IDN (international domain names)

Notes:
1. I used idna_convert.class.php to convert from idna punnycode domain names to ascii domain names
Reference: http://www.phpclasses.org/package/1509-PHP-Convert-from-and-to-IDNA-Punycode-domain-names.html
IDNA stands for Internationalized Domain Names for Applications. It is a standard described in RFC 3490, RFC 3491 and RFC 3492. It is used to allow language specific characters in domain names, like the umlauts in German, accents in latin languages like French, or even chinese characters.

This class allows you to convert domain names between the encoded Punycode notation and the decoded 8bit (UTF-8) notation. It simplifies the use of domain names defined with IDNA in applications or scripts.

2. All the domain naming rules were taken from
Reference: http://en.wikipedia.org/wiki/Domain_Name_System
- The right-most label conveys the top-level domain; for example, the domain name www.example.com belongs to the top-level domain com.
- The hierarchy of domains descends from right to left; each label to the left specifies a subdivision, or subdomain of the domain to the right. For example: the label example specifies a subdomain of the com domain, and www is a sub domain of example.com. This tree of subdivisions may have up to 127 levels.
- Each label may contain up to 63 characters. The full domain name may not exceed a total length of 253 characters in its external dotted-label specification. In the internal binary representation of the DNS the maximum length requires 255 octets of storage. In practice, some domain registries may have shorter limits.[citation needed]
- DNS names may technically consist of any character representable in an octet. However, the allowed formulation of domain names in the DNS root zone, and most other sub domains, uses a preferred format and character set. The characters allowed in a label are a subset of the ASCII character set, and includes the characters a through z, A through Z, digits 0 through 9, and the hyphen. This rule is known as the LDH rule (letters, digits, hyphen). - - - -- Domain names are interpreted in case-independent manner. Labels may not start or end with a hyphen.
- A hostname is a domain name that has at least one IP address associated. For example, the domain names www.example.com and example.com are also hostnames, whereas the com domain is not.

3. All the valid TLD's were taken from
Reference 1: http://data.iana.org/TLD/tlds-alpha-by-domain.txt
Reference 2: http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains

Thursday, February 18, 2010

Create Grid of 7 days from 2 dates

public function create_grid($start_date, $end_date) {
$days = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');

echo "";
$end_date = date('Y-m-d', strtotime("{$end_date} + 1 day"));
$start_date_day = date('D', strtotime("{$start_date}"));
$i = 0;
if ($start_date_day != $days[$i]) {
echo "";
while($days[$i] != $start_date_day) {
echo "";
$i++;
}
}

$curday = "";
while ($start_date != $end_date) {
$curday = date('D', strtotime("{$start_date}"));
if($curday == "Mon") {
echo "";
}

echo "";

$start_date = date('Y-m-d', strtotime("{$start_date} + 1 day"));
if($curday == 'Sun') {
echo "";
}
}

$i = 6;
if ($curday != $days[$i]) {
while($days[$i] != $curday) {
echo "";
$i--;
}
echo "";
}

echo "
";
echo $curday.', '.$start_date;
echo "
";

}

Thursday, January 28, 2010

Sort Object by Member

function sort_object($data, $member, $direction)
{
//reset array;
sort($data);

for ($i = count($data) - 1; $i >= 0; $i--)
{
$swapped = false;

for ($j = 0; $j < $i; $j++)
{
if ($direction == 1)
{
if ( $data[$j]->{$member} < $data[$j + 1]->{$member} )
{

$tmp = $data[$j];
$data[$j] = $data[$j + 1];
$data[$j + 1] = $tmp;
$swapped = true;
}
}
else
{
if ( $data[$j]->{$member} > $data[$j + 1]->{$member} )
{
$tmp = $data[$j];
$data[$j] = $data[$j + 1];
$data[$j + 1] = $tmp;
$swapped = true;
}
}
}

if (!$swapped)
{
return $data;
}
}
}

Sort Array by Field

function sort_array($data, $member, $direction)
{
//reset array;
sort($data);
for ($i = count($data) - 1; $i >= 0; $i--)
{
$swapped = false;

for ($j = 0; $j < $i; $j++)
{
if ($direction == 1)
{
if ( $data[$j][$member] < $data[$j + 1][$member] )
{
$tmp = $data[$j];
$data[$j] = $data[$j + 1];
$data[$j + 1] = $tmp;
$swapped = true;
}
}
else
{
if ( $data[$j][$member] > $data[$j + 1][$member] )
{
$tmp = $data[$j];
$data[$j] = $data[$j + 1];
$data[$j + 1] = $tmp;
$swapped = true;
}
}
}
if (!$swapped)
{
return $data;
}
}
}

Tuesday, December 22, 2009

Check if a date is in the past

$diff = (number_format((time() - strtotime($date_to_check)) / (60 * 60 * 24), 2));

if ($diff > 0)
{
echo "$date is $diff days ago from today";
}

Monday, December 21, 2009

Ajax with JSON returned from response (Prototype)

Javascript code:
----------------
edit_info = function(id) {
url = 'www.test.com/get_info?id=' + id;
new Ajax.Request(url, {
method: 'post',
onComplete: function(req) {
var data = eval("("+req.responseText+")");
$('email').value = data['email'];
$('city').value = data['city'];
}
});
}

PHP code:
---------
public function get_info() {
$info = db.query('select * from info where id='.$_REQUEST['id']);
echo json_encode($info);
exit;
}