SL8R.co.uk - Code Zone

Code, Code and Code

SL8R.co.uk - Code Zone header image 1

PHP: Defining Constants

April 23rd, 2008 · 1 Comment

To define a constant, use the format:

define(constant_name,constant_value,case_insensitive)

e.g.

define(”MYCONSTANT”,”This is the value of the constant”,false);
print “Constant is ” . constant(”MYCONSTANT”);
?>

→ 1 CommentTags: Code

PHP: Page Inclusion using GET selection

April 18th, 2008 · No Comments

Sample code to handle page inclusion based on get values 

// parse the passed value
switch($_GET['page'])
{
  // check for page1
  case(’page1′):
  include ‘page1.php’;
  break;
  // check for page2
  case(’page2′):
  include ‘page2.php’;
  [...] Continue Reading…

→ No CommentsTags: Code

PHP: Encoding HTML Special Characters

April 18th, 2008 · 1 Comment

When working with untrusted information it is always worth running it through the htmlspecialchars function.
This function converts characters that are used by html into safer versions, e.g. ‘<’ becomes [...] Continue Reading…

→ 1 CommentTags: Code

PHP: Add a number of days to a date

April 11th, 2008 · 1 Comment

example code to add a number of days to a date

// add 5 days
$daystoadd=5;
// calculate hours
$hours=$daystoadd * 24;
// get today
$dd=date(d);
$mm=date(m);
$yy=date(y);
// calculate the new date
$newdate=date(”d-m-y”, mktime($hours, 0, 0, $mm, $dd, [...] Continue Reading…

→ 1 CommentTags: Code

PHP: Format and show an expiration date

April 8th, 2008 · No Comments

A useful routine to calculate and show an expiration date based on a given number of hours

// Hours to expiration
$iHrs = 72;
// Date from database
$dbDate = ‘2008-04-08 16:53:19′;
// obtain [...] Continue Reading…

→ No CommentsTags: Code

ASP: Teaser Text

April 7th, 2008 · No Comments

An early routine written in ASP to cut off a given string after a given number of words:

strText = “This is some example text To prove the Get teaser [...] Continue Reading…

→ No CommentsTags: Code

Shell Script: Random Number

April 5th, 2008 · 2 Comments

To get a random number at a shell script in Unix (I tried this on AIX 5 and it worked) use $RANDOM

echo $RANDOM
26558
echo $RANDOM
16737
echo $RANDOM
11669

→ 2 CommentsTags: Code

J2ME: Splash Screen Timer

April 4th, 2008 · No Comments

Timer Example

private Timer myTimer;
  myTimer = new Timer();
  // Show Splash Screen
  myTimer.schedule( new waitSplash(), 2000 );

// process the splash screen timer
  private void dismiss()
  {
  myTimer.cancel();
  // change [...] Continue Reading…

→ No CommentsTags: Code

J2ME: Get IMEI Number

April 4th, 2008 · No Comments

To get an IMEI number:

// Get Sony Ericsson IMEI
String imeiSE = System.getProperty(”com.sonyericsson.imei” );
// Siemens
String imeiS = System.getProperty(”com.siemens.IMEI”);
// Motorola:
String imeiM = System.getProperty(”IMEI”);

For more information about IMEI: http://en.wikipedia.org/wiki/IMEI

→ No CommentsTags: Code

J2ME: the future

April 3rd, 2008 · 2 Comments

I recently read an article indicating the potential demise of J2ME in favour of running J2SE on mobile devices. One reason given for this is due to J2ME’s sandbox [...] Continue Reading…

→ 2 CommentsTags: Comment