Archive

Archive for the ‘Web Development’ Category

[PHP] Converting a value to MAC address format

October 20th, 2009

php_codeI just want to post this since someone ask about it. It might help if someone in this world is searching for an answer with the same problem my friend does. This is about converting a value of 0014:f8c4:9e32 or 0014f8c49e32 to 00:14:f8:c4:9e:32

Now here’s some answers for that…

function convertMACAddress($input)
{
    // clean up unwanted characters
    $input = preg_replace( '/[^a-zA-Z0-9]/', '', $input);

    // initiate character positioning
    $pos = 0;

    // declare output container
    $output = '';

     // if given MAC is invalid, terminate process and return an error
     if (strlen($input) < 12)
     {
           return '[Unrecognized MAC address]';
     }

    // initiate convertion...
    for ($i = 0; $i < 6; $i++)
    {
           if ($i == 0)
           {
                  $output .= substr($input, $pos, 2);
           }
           else
           {
                   $output .= ':'.substr($input, $pos, 2);
            }
            $pos += 2;
     }

      return $output;
}

That’s it… Problem solved. :) If need a sample code, please download the source -> Mac Convert (8) — Have fun coding..

Camilo III Info.Tech, PHP, Web Development

Freelance Freedom by NC Winters

May 20th, 2009

These comic trips by N.C. Winters relates my work pretty much…

Camilo III Administration, Personal, Web Development, Wooow! , , , ,

Oracle Database 10g Express Edition

May 20th, 2009

Oracle Database 10g Express Edition
Free to develop, deploy, and distribute

Oracle XEOracle Database 10g Express Edition (Oracle Database XE) is an entry-level, small-footprint database based on the Oracle Database 10g Release 2 code base that’s free to develop, deploy, and distribute; fast to download; and simple to administer. Oracle Database XE is a great starter database for:

* Developers working on PHP, Java, .NET, XML, and Open Source applications
* DBAs who need a free, starter database for training and deployment
* Independent Software Vendors (ISVs) and hardware vendors who want a starter database to distribute free of charge
* Educational institutions and students who need a free database for their curriculum

With Oracle Database XE, you can now develop and deploy applications with a powerful, proven, industry-leading infrastructure, and then upgrade when necessary without costly and complex migrations. Read what users say about Oracle Database XE.

Oracle Database XE can be installed on any size host machine with any number of CPUs (one database per machine), but XE will store up to 4GB of user data, use up to 1GB of memory, and use one CPU on the host machine.

After installation, be sure to register for an exclusive Oracle Database 10g Express Edition Discussion Forum hosted by Oracle expert Tom Kyte—click on the “Registration” link on XE’s Database homepage.

Camilo III Info.Tech, Software Development, Web Development , , ,

[PHP] Shortcuts of If-Else statement

April 5th, 2009

When I learn PHP last September 2005, I was little bit confuse in PHP if-else statement… especially a statement contains with ? and : but somehow, I got it right. I post this cause somebody ask again what’s the difference. So told him, its all the same and its just a shortcuts.

<?php

$authenticated = true;

// [1] standard if-else statement
if ($authenticated)
{
     echo
‘YES’;
}
else
{
      echo ‘NO’;
}

// same with [1] :P
if ($authenticated) { echo ‘YES’; } else { echo ‘NO’; }

// [2] lil bit shortcut
if ($authenticated)
      echo ‘YES’;
else
      echo ‘NO’;

// [3] the shortcut
echo $result = ($authenticated) ? ‘YES’ : ‘NO’;

?>

Or let me say its an evolution of if-else statement… Hahaha.. or maybe the laziness of the programmer. :P So got it? hehehehe..

Camilo III Info.Tech, PHP, Web Development , ,

[PHP] How to upload a file

April 2nd, 2009
Comments Off

I would like to share this script to all since most of my friends ask how to create an upload script using PHP.

Download the PHP script at;

  1. Main Download: Simple Upload Demo (5)
  2. Mirror 1: simple_upload.zip

Upload File Demo: http://www.cable21.net/camilord/simple_upload/index.html

Modification according to your preferred setup

Its default upload directory is uploads/ and to change this, just change the line 19;

// set upload destination
$uploaddir = “uploads/”;

In the script, it is capable to validate allowed file types. As default, images files are only allowed to be uploaded. To change this, just edit the upload.php at line 37.

// allowed file types
$validMIME = array(‘jpg’,‘jpeg’,‘bmp’,‘png’,‘gif’);

Just add any file extension you want to allow… Sample;

// allowed file types
$validMIME = array(‘jpg’,‘jpeg’,‘bmp’,‘png’,‘gif’,‘doc’,‘zip’,‘pdf’);

So I just allowed Document, Zip and PDF files…

That’s all.. I think everything is understandable.. hehehe.. Please read also the comments.

Camilo III Info.Tech, PHP, Web Development , , , , , ,

PHP Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 4800 bytes)

February 9th, 2009

When I first encountered this error, I thought something wrong with my apache-php integration. Thank God it’s not the one I thought.

This PHP Fatal error message will be encountered if your PHP script memory requirements exceed the default 8MB limit. Somehow, you can overcome this by doing two methods.

1. Set Resource Limits in /etc/php.ini

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 45 ; Maximum execution time of each script
max_input_time = 60 ; Maximum amount may spend parsing request data
memory_limit = 12M ; Maximum amount of memory a script may consume (8MB)

2. Initiate a function to set the Resources Limit

ini_set("memory_limit","12M");

Why so serious?!? that’s it… your done! :)

Camilo III Administration, Info.Tech, Web Development , , , , , , ,