Get Current file path,Directory Path, Parent Directory Path in PHP

$module_name = basename(dirname(__FILE__));
__FILE__ returns the filename of the script that is currently being run.
dirname returns the directory of a given filename.
basename() returms the filename component of path. To put it better: it strips any “parent” directories off a given string.

The constant __FILE__ in PHP always returns the absolute path to the script file that’s currently active – the PHP file in which the code line is being run right now. Function dirname() returns the directory part of the given path. Continue reading Get Current file path,Directory Path, Parent Directory Path in PHP

Web font – how to use a special font in your website

The easiest way to use Web Fonts in your website

CSS @font-face rule, a way of linking to TrueType (TTF) and OpenType fonts (EOT) to your website text documents.

About Browser Support of Web Fonts : Safari has supported this type of font linking since version 3.1, and Opera has announced that they plan to support it in Opera 10. Firefox 3.5 onwards only downloads the fonts as needed, so a stylesheet can list a whole set of fonts of which only a select few will actually be used.

Continue reading Web font – how to use a special font in your website

Get some preliminary idea about web fonts

This tutorial may seem to be little complex, as I found it in some site and I have just posted it here as it is. But later I have written more easy contemporary guide on web fonts to use it in your website.

It may be your requirement : I have a beautiful font and I want to use this font in my website. I want to make sure that everyone can see this font using any operating system or browser. What shall I do for it. What is the CSS code to use a font in my webserver. The first step I have made that I have uploaded the font file in my website (running in a web server) using FTP method. Then what CSS code I shall use to use this font?

Continue reading Get some preliminary idea about web fonts

Static member function in C++

Static data types can be accessed without instantiation of the class in C++. This is applicable for static functions also. The static member functions are accessible even when the class is not instantiated.

The Properties of static member function in C++ :

  • can be called, even when a class is not instantiated
  • cannot be declared as virtual.
  • cannot access THIS pointer.
  • Can access only – static member data, static member functions, data and functions outside the class.

The differences between a static member function and non-static member functions are as follows.

  • A “static member function” can access only “static member data, static member functions and data and functions outside the class”. A non-static member function can access all of the above including the static data member.
  • A static member function property : can be called, even when a class is not instantiated.
  • Non-static member function property : can be called only after instantiating the class in an object.

  • A static member function property : cannot be declared virtual.
    Non-static member function property : can be declared as virtual
  • A static member function property : Cannot have access to the ‘this’ pointer of the class.

JavaScript / Any language: Delete a specific array element and shift other elements after deletion

How to delete a specific array element and shift other elements after deletion in JavaScript or any other programming languages

Here I have used an array , to be precise, predefined fixed array I have used here.
Initial array is [15,10,20,22,1,3,6].

Then I have decided to delete an item based on a comparison, here I have chosen to delete item 20.
After deletion the array will be : [15,10,22,1,3,6]

Initially after assigning the array by the statement var myArray = [15,10,20,22,1,3,6];
myArray[6]=6 and
array length = 7 found by the statement myArray.length;

After deletion the the item 20 will be deleted i.e myArray[2] and (after delete) myArray[2] will hold (before delete) myArray[3] i.e 22, (after delete) myArray[3] will hold (before delete) myArray[4] value i.e 1.

So , after deletion the array elements will be as follows :
array length = 6

Below we have used JavaScript splice() method, but this shifting and delete can be done without this method. I am giving you a hint.

I have not used this splice() method in the following JavaScript code snippet, you can use it also instead of the code in Gray.

Make deletion and shifting without splice() method in JavaScript. The following algorithm will work in any programming language.

The algorithm :
Step1: first reach the item which you want to delete by a FOR LOOP,
Step 2: Then get the ARRAY INDEX of that element.
Step 3: Then assign next array element to that element. Assign next array element to that element to shift and continue the process.

// Make shifting a global variable.
var shifting = 0;
for(var i = 0; i <= myArray.length-1; i++) { if(myArray[i] == 20) shifting = 1; if(shifting == 1) myArray[i] = myArray[i+1]; }

Delete an array element and shift the rest of the element by the help of SPLICE() method in JavaScript.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var myArray = [15,10,20,22,1,3,6];
document.write("<br />"+myArray);
document.write("<br />Before delete Array Length : "+myArray.length);
for(var i = myArray.length-1; i >= 0; i–)
if(myArray[i] == 20)
document.write("<br />After deleting item 20 the array becomes : "+myArray);
document.write("<br />Array Length : "+myArray.length);


Sorting arrays in Javascript, Numeric sorting

If you normally sort an array, then it is sorted alphabetically or lexically.

<title>Untitled Document</title>
<script type="text/javascript">
var myarray = [10,1,100,23,2,33,4];


The output will be : 1,10,100,2,23,33,4
Because the array myarray is sorted alphabetically.

But if you want to sort it numerically then pass a function in argument as mentioned below.

<script type="text/javascript">
var myarray = [10,1,100,23,2,33,4];
myarray.sort(function f(a,b) { return a-b; });


Mastering JavaScript Arrays, Know in details

The best tutorial I have found on JavaScript Arrays till date is here :

  • Creating A New Array
  • Initializing An Array
  • Storing Data In An Array
  • Multi-Dimensional Arrays
  • How JavaScript Arrays are passed to a function : Javascript Arrays Are Passed By Reference
  • Javascript Arrays Are Assigned By Reference
  • Passing Arrays As Values
  • Array.length
  • Javascript Does Not Support Associative Arrays
  • Array Methods Reference