LoRz

Monday, June 30, 2008

 

PHP Video Tutorials


  1. KillerPHP
  2. PHP Video Tutorials

 

Compute Age in PHP


Code to compute age in PHP

<?php

list($bYear, $bMonth, $bDay) = explode("-", $birthday);

$cMonth = date('n');
$cDay = date('j');
$cYear = date('Y');

if(($cMonth >= $bMonth && $cDay >= $bDay) || ($cMonth > $bMonth)) {
$age = $cYear - $bYear;
} else {
$age = 0;
}

echo $age;
?>

The date format in the code above is yyyy-mm-dd.

If you are to use mm/dd/yyy format change the code
list($bYear, $bMonth, $bDay) = explode("-", $birthday);
to
list($bMonth, $bDay, $bYear) = explode("/", $birthday);

Thursday, June 26, 2008

 

Access GMail in Nokia N95


I prefer using the IMAP feature of Gmail.


Steps
  1. Go to Messaging - Email
  2. Select Options
  3. Select E-mail settings from the menu
  4. Select Connection settings
  5. Select Incoming e-mail
  6. Fill up the fields
  7. User name: Gmail username
    Password: Gmail password:
    Incoming mail server: imap.gmail.com
    Access point in use: depends on your connection
    Mailbox name: depends on your choice
    Mailbox type: IMAP4
    Secutiy (ports): SSL/TLS
    Port: Default
  8. Go back to Connection settings
  9. Select Outcoming e-mail
  10. Fill up the fields

  11. My e-mail address: Gmail e-mail address
    User name: Gmail username
    Password: Gmail password:
    Outgoing mail server: smtp.gmail.com
    Access point in use: depends on your connection
    Mailbox name: depends on your choice
    Secutiy (ports): SSL/TLS
    Port: 587

  12. Go back to Messaging - Email
  13. Select Options
  14. Retrieve e-mail

Tuesday, June 24, 2008

 

Instant Messaging in Nokia N95


I'm using Fring when instant messaging in my Nokia N95. It supports many protocols like Yahoo, Google Talk, Skype call in Fring.

Note: Install the application in your memory card so it won't be removed when updating your firmware.

 

Displaying Values in PHP


A simple code to have a formatted view of values when printing/debugging variables, objects, arrays, etc..

echo '<pre>', print($variable), '</pre>';

Thursday, June 19, 2008

 

Adding Media Player and Quick Time in HTML


Sample code for including media player

<object id="MediaPlayer" width="480" height="360" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components..." type="application/x-oleobject">
<param name="fileame" value="mtv.mpg">
<param name="ShowControls" value="true">
<param name="ShowStatusBar" value="false">
<param name="ShowDisplay" value="false">
<param name="autostart" value="false">
<embed type="application/x-mplayer2" str="mtv.mpg" name="MediaPlayer" width="480" height="360" ShowControls="1" ShowStatusBar="0" ShowDisplay="0" autostart="0"></embed>
</object>

Sample code for including quicktime

<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="500" width="500">
<param name="src" value="mtv.mpg">
<param name="autoplay" value="false">
<param name="target" value="myself">
<param name="controller" value="false">
<param name="href" value="test.wmv">
<param name="type" value="video/quicktime" height="256" width="320">
<embed src="mtv.mpg" height="500" width="500" autoplay="false" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/" controller="true" href="mtv.mpg" target="myself"></embed>
</object>

Wednesday, June 18, 2008

 

Firebug for Firefox 3


Download Firebug 1.2.x for Mozilla Firefox 3 because older versions of Firebug won't work in Firefox 3.


Tuesday, June 17, 2008

 

Unable to set database connection charset: utf8 in CodeIgniter


If you have experiencing this error in CodeIgniter using CodeIgniter 1.6.x and MySQL 4.0


Unable to set database connection charset: utf8

It is setting the character set and collation for the database to which you are connecting.

A quick and dirty way of fixing this is looking for the db_set_charset() function on your system/database/drivers/your_driver/your_driver_driver.php

function db_set_charset($charset, $collation)
{
return TRUE;
//return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id);
}

A better fix


function db_set_charset($charset, $collation)
{
if($charset == false || $collation == false)
{
return true;
}
else
{
return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id);
}
}


Set the following in your database.php

$db['default']['char_set'] = false;
$db['default']['dbcollat'] = false;

Monday, June 16, 2008

 

Enabling cURL in XAMPP


Search for all the PHP ini files in the XAMMP directory including php4.ini/php5.ini


Look for the lines

;extension=php_curl.dll
;extension=php_openssl.dll

Uncomment the lines to enable the extension

extension=php_curl.dll
extension=php_openssl.dll

Restart Apache. To verify, you should see in the PHP info [phpinfo();] that cURL is enabled or you could try testing the following code


<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://www.google.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$output = curl_exec($ch);

curl_close($ch);

$output = str_replace('Google', 'Test', $output);

echo $output;

?>


Sunday, June 15, 2008

 

Credit Card Generator


Online Credit Card Generator


A good discussion of credit card generation using Luhn Formula.

It is useful for testing online payment transactions. Below are some sample credit card numbers.

Mastercard

5341897790221515
5537988621049060
5243922045196558
5153322209529918
5165209231276376
5334676997859858
5181712635852494
5178302989876631
5596412771306202
5234433320094642

VISA 16 digit

4929244915211514
4532093314408141
4716486708213879
4485791832466205
4929238452326396
4716007760893323
4929054317354121
4916180966946373
4929355796422937
4916580586170710

VISA 13 digit

4532194641617
4929933423903
4539080898482
4024007168228
4024007120450

American Express

375036825305981
379612889775990
375591527443753
373893406385168
341565025177924

Discover

6011397261054567
6011947108265873
6011395087227045

Diners Club

30140606700415
38566427390576
30091141757453

enRoute

214960218143805
214981086786806
201407572161861

JCB 15 digit

210094538436428
180004290191166
180098506255716

JCB 16 digit

3158195945475582
3158490241976544
3158712307954408

Voyager

869986290103613
869938875378185
869949834274563

Saturday, June 14, 2008

 

Posting source code on blogger


Download WebCodeFormatter which is Java application and paste you code in the window. Click Transform. Some characters that are converted are single and double quotes.


Sample code

if(!inWpsDir()) {
$wps_dir = dirname(__FILE__);
error_message("Please cd to the $wps_dir and run install.php");
exit(1);
}
if($err = validate_php_env($reqd_wps_ext)) {
error_message("Missing required PHP extention(s) for WPS Toolkit: $err");
exit(1);
}

And you will see the this code converted to an acceptable format for blogger.


 

Code to create a thumbnail like table in PHP

Code to create a thumbnail like table in PHP

$colsPerRow = columns to be displayed per row
$contents = usually array or result of a SQL query


<?php
print '<table width="90%" border="0" cellpadding="5" cellspacing="0" align="center">';

$colsPerRow = 6;
$colWidth = (int)(100/$colsPerRow);
$counter = 0;

foreach ($contents as $content)
{
if ($counter % $colsPerRow == 0)
{
print '<tr>';
}

print '<td valign="top" align="center" width="' . $colWidth . '%">$content</td>';

if ($counter % $colsPerRow == $colsPerRow - 1)
{
print '</tr>';
}

$counter += 1;
}

if ($counter % $colsPerRow != 0)
{
while ($counter++ % $colsPerRow != 0)
{
print '<td width="' . $colWidth . '%"> </td>';
}

print '</tr>';
}

print '</table>';
?>

Archives

June 2008   July 2008   August 2008   September 2008  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]