Short Tag – Web Development Blog

Entries for June, 2010

Get month, day, year from timestamp functions [PHP]

Today I thought I can share you a few of my functions. Today’s article is an easy one, but I use the functions in almost all my websites, so I thought they can be useful to you.
So here are a few functions that get the year,month,day,hour,minute,second from a time stamp, similar to the MYSQL functions. [...]

AS3 get file contents, load and work with XML

As3 has a few classes that ease our work with external files (for example with XMLs).
First I will show you how to load an external file:

var file:string = "myfile.txt";
var ur:URLRequest = new URLRequest(file);
var ul:URLLoader = new URLLoader();
ul.addEventListener(Event.COMPLETE, loaded);
ul.load(ur);

function loaded(e:Event):void
{
var str:String = e.target.data;
trace(‘Loaded data is:’+str);
}

In the example above str variable will hold the content of a [...]

ActionScript 3 getURL()

Among the big changes in AS3 is the change of getURL() function. This function has been eliminated from AS3, since this language has became an Object Oriented programming language and it followes the rules of ECMAScript.
In AS2 to open a url (to create a link in flash) we had to use getURL function.
In AS3 we [...]

AS3 random range

As3’s Math.random() function returns a random decimal number between 0 and 1. Here is a function that uses Math.rand() to generate a random number within a specified range:

function rand(minNum:Number, maxNum:Number):Number
{
return (Math.floor(Math.random() * (maxNum – minNum + 1)) + minNum);
}

This function return a random number within a range. It is much like PHP’s rand() function.
Usage:

var i:Number [...]

AS3 string replace function

function replace(input:String, replace:String, replaceWith:String):String
{
var sb:String = new String();
var found:Boolean = false;

var sLen:Number = input.length;
var rLen:Number = replace.length;

for (var i:Number = 0; i < sLen; i++)
{
if(input.charAt(i) == replace.charAt(0))
{
found = true;
for(var j:Number = 0; j < rLen; j++)
{
if(!(input.charAt(i + j) == replace.charAt(j)))
{
found = false;
break;
}
}

if(found)
{
sb += replaceWith;
i = i + (rLen – 1);
continue;
}
}
sb += input.charAt(i);
}
return sb;
}

This function is [...]

Stream Context in PHP (The CURL alternative)

In PHP there are several ways to get the content of a URL.
A well known method is using the function file_get_contents().
Another way would be using the cURL classes. The thing is, cURL may not be available an all hosts and you might be forced to use file_get_contents, or you just want to use file_get_contents() because [...]

JQuery and Innerfade (slideshow plugin)

Jquery is a library of Javascript functions and classes that can make Javascript programming a lot easier. Cross-browser Ajax means one line of code with JQuery. Animations, moving objects are easy to do with Jquery.
And it’s absolutely free!
Official website:
http://jquery.com/
Now… what is innerfade?
Innerfade is a plugin for JQuery. You can use innerfade for slideshows. Innerfade [...]

UL, LI – HTML and Css lists, horizontal positioning

The HTML lists (with CSS styling) are very handy for assembling HTML designs. They are very useful when creating menus, especially for horizontal menus. You could use tables to create a horizontal menu, but tables are overrated, they load harder than divs or lists and they are not good for SEO. You could use divs, [...]

PHP constants

The constants in PHP (and in any other programming language) are used to store data.
So, what’s the difference between variables and constants?
They both store data, but a variable can be modified anywhere in the code, and a constant cannot be modified. You can try to modify it, PHP won’t return any error, but it won’t [...]

CGI script and PHP

CGI it’s not a programming language. CGI(Common Gateway Interface) it’s just an interface between the http server and the software residing on the host machine.
You can write CGI script using a variety of programming languages: PHP, PERL, C, C++, etc.
Why use CGI scripts?
CGI scripts are very useful when you need to combine PHP with other [...]